308

I'd like to git clone the contents of a repository I have on GitHub. When I git clone (git@github:me/name.git...) I get a folder called name/ and inside name I have my contents... How do I get JUST the contents?

2

7 Answers 7

415

If the current directory is empty, you can do that with:

git clone [email protected]:me/name.git . 

(Note the . at the end to specify the current directory.) Of course, this also creates the .git directory in your current folder, not just the source code from your project.

This optional [directory] parameter is documented in the git clone manual page, which points out that cloning into an existing directory is only allowed if that directory is empty.

Sign up to request clarification or add additional context in comments.

7 Comments

Unfortunately, this doesnt work if there are other, non related directories already in the same dir. Looking for a solution. The error message is: "fatal: destination path '.' already exists..."
The directory git clones into must be empty
@HumaunRashid Add a . as discussed in the answer: git clone https://github.com/humaun21/Test . . And yes, [email protected]/name.git is a placeholder for whatever your actual git repo address is.
@JohnLittle Had the same problem, turns out there is a hidden .DS_Store file, that hides there. Simply rm .DS_Store and you're good to go.
If you are working on linux OS, you need to be sure the directory is empty including checking for hidden files and subdirectories. You can do that with ls -a. You should have only . and .. as output. This wont work otherwise
|
188

Unfortunately, this doesn't work if there are other, non-related directories already in the same dir. Looking for a solution. The error message is: "fatal: destination path '.' already exists...".

The solution in this case is:

git init git remote add origin [email protected]:me/name.git git pull origin master 

This recipe works even if there are other directories in the one you want to checkout in.

6 Comments

Hey in this I am getting an error like Permission denied <public key>. The remote end hung up unexpectedly.
Shouldn't it be github.com there after git remote ..., and not just github?
This answer should have been accepted one. works perfectly.
I read elsewhere here that you need to run git fetch --all before the git pull origin master, because if there are other branches on the repo, git pull won't get those unless you use fetch first. Is this correct?
But then the other non-related directories and all their files will show up as untracked changes.
|
49

If the folder is not empty, a slightly modified version of @JohnLittle's answer worked for me:

git init git remote add origin https://github.com/me/name.git git pull origin master 

As @peter-cordes pointed out, the only difference is using https protocol instead of git, for which you need to have SSH keys configured.

3 Comments

What version of git are you running? This didn't work for me. It still won't let me set it up because the dir isn't empty
@guribe94 git version 2.5.0
This is the same answer, just using anonymous https instead of git-protocol over ssh (requiring a github account with an ssh keypair set up).
24

You can specify the destination directory as second parameter of the git clone command, so you can do:

git clone <remote> . 

This will clone the repository directly in the current local directory.

1 Comment

This works only if current directory isn't empty.
3

to clone git repo into the current and empty folder (no git init) and if you do not use ssh:

git clone https://github.com/accountName/repoName.git . 

Comments

2

this worker for me

git clone <repository> . 

Comments

2

I know this question is old but please notice that git pull will abort if there is local files that matches the remote one, a solution for that would be to make a reset after pulling like this:

git init git remote add origin REMOTE_REPO_URL.git git pull origin master git reset --hard FETCH_HEAD 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.