tags:

views:

150

answers:

2

I have directory A with files matching directory B. Directory A may have other needed files. Directory B is a git repo.

I want to clone directory B to directory A but git-clone won't allow me to since the directory is non-empty.

I was hoping it would just clone .git and since all the files match I could go from there?

I can't clone into an empty directory because I have files in directory A that are not in directory B and I want to keep them.

Copying .git is not an option since I want refs to push/pull with and I don't want to set them up manually.

Is there any way to do this?

Update: I think this works, can anyone see any problems? -->

cd a
git clone --no-hardlinks --no-checkout ../b a.tmp 
mv a.tmp/.git .
rm -rf a.tmp
git unstage # apparently git thinks all the files are deleted if you don't do this
+1  A: 

Maybe I misunderstood your question, but wouldn't it be simpler if you copy/move the files from A to the git repo B and add the needed ones with git add?

UPDATE: From the git doc:

Cloning into an existing directory is only allowed if the directory is empty.

SOURCE: http://www.kernel.org/pub/software/scm/git/docs/git-clone.html

Roberto Aloi
No, the owner and the files could be arbitrary. This is for a situation with multiple developers. We all have existing directories and only one currently has a git checkout. We all largely have the same subset of files so we want to have the other developers be able to clone while retaining their files. And it should be as elegant and convenient as possible.
Darvan Shovas
Honestly, I don't see the point of developing in such a condition. Can't you use branches and merge operations? Or having sub-repositories with external dependencies? Why would you want to rely on a single "git checkout"?
Roberto Aloi
A "single git checkout" is not the point of the whole ordeal. It's just that this is the way it is and we need a way to move forward. I updated the original question with a solution that appears to be working. I appreciate the feedback, though.
Darvan Shovas
A: 

Given a directory, a, of files files matching a git repository, b, of tracked files:

git clone --no-checkout b a/a.tmp # might want --no-hardlinks for cloning local repo
mv a/a.tmp/.git a/
rm -rf a/a.tmp
cd a
git unstage # git thinks all files are deleted, this reverses that behaviour
Darvan Shovas