Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: What's the best practice to "git clone" into an existing folder?

Tags:

git

I have a working copy of the project, without any source control meta data. Now, I'd like to do the equivalent of git-clone into this folder, and keep my local changes.

git-clone doesn't allow me to clone into an existing folder. What is the best practice here?

like image 678
ripper234 Avatar asked Mar 21 '11 13:03

ripper234


People also ask

Can you git clone into an existing directory?

However, you can only clone into an existing directory only when it is empty. Otherwise, git will complain that the destination path already exists and is not an empty directory. That's all about cloning a Git repository into a specific folder.

How do you clone a git repository into 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 .

When you clone a repo where does it go?

When you clone a repository, you copy the repository from GitHub.com to your local machine. Cloning a repository pulls down a full copy of all the repository data that GitHub.com has at that point in time, including all versions of every file and folder for the project.

Can I just copy a git repository to another directory?

The correct command is rsync -azv --exclude '. git' source/ destination/ , which copies contents of source folder to destination folder.


1 Answers

This can be done by cloning to a new directory, then moving the .git directory into your existing directory.

If your existing directory is named "code".

git clone https://myrepo.com/git.git temp mv temp/.git code/.git rm -rf temp 

This can also be done without doing a checkout during the clone command; more information can be found here.

like image 162
amicitas Avatar answered Sep 29 '22 01:09

amicitas