Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I clone into a non-empty directory?

Tags:

git

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 
like image 719
Dale Forester Avatar asked Mar 09 '10 17:03

Dale Forester


People also ask

How do I clone a git repository to a specific folder?

To clone git repository into a specific folder, you can use -C <path> parameter, e.g. Although it'll still create a whatever folder on top of it, so to clone the content of the repository into current directory, use the following syntax: cd /httpdocs git clone [email protected]:whatever .

Can you clone a bare repository?

In order to clone your repository to create a new bare repository, you run the clone command with the --bare option. By convention, bare repository directory names end with the suffix . git , like so: $ git clone --bare my_project my_project.


1 Answers

This worked for me:

git init git remote add origin PATH/TO/REPO git fetch git reset origin/master  # Required when the versioned files existed in path before "git init" of this repo. git checkout -t origin/master 

NOTE: -t will set the upstream branch for you, if that is what you want, and it usually is.

like image 164
cmcginty Avatar answered Sep 20 '22 08:09

cmcginty