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?
-
1possible duplicate of [How do you clone a git repository into a specific folder?](http://stackoverflow.com/questions/651038/how-do-you-clone-a-git-repository-into-a-specific-folder) – bryanbraun May 14 '14 at 05:20
-
To actually skip downloading unneeded objects to save network resources: https://stackoverflow.com/questions/600079/how-do-i-clone-a-subdirectory-only-of-a-git-repository/52269934#52269934 – Ciro Santilli OurBigBook.com Sep 11 '18 at 07:20
7 Answers
If the current directory is empty, you can do that with:
git clone git@github.com: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.

- 21,987
- 6
- 62
- 97

- 446,582
- 72
- 411
- 327
-
4Unfortunately, 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..." – John Little May 23 '13 at 10:58
-
18
-
what is git@github.me? Is it the path of the repository? It's not working for me. I am trying this and I want only files inside Test folder... git clone https://github.com/humaun21/Test.git I want to get only the files inside Test folder. But It's not working. I creates a Test folder which contains my folder. But I want only files inside Test folder? – Humaun Rashid Nayan Mar 02 '16 at 11:41
-
1@HumaunRashid Add a `.` as discussed in the answer: `git clone https://github.com/humaun21/Test .` . And yes, `git@github.me/name.git` is a placeholder for whatever your actual git repo address is. – Aaron Campbell May 23 '16 at 16:26
-
2@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. – Selrond Mar 22 '17 at 05:29
-
1If 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 – Ayo Makanjuola Jun 02 '18 at 20:31
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 git@github.com:me/name.git
git pull origin master
This recipe works even if there are other directories in the one you want to checkout in.

- 10,707
- 19
- 86
- 158
-
Hey in this I am getting an error like Permission denied
. The remote end hung up unexpectedly. – Stan Feb 20 '14 at 07:24 -
Shouldn't it be `github.com` there after `git remote ...`, and not just `github`? – Armen Michaeli May 21 '15 at 21:18
-
6
-
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? – Alex G Nov 22 '18 at 11:22
-
But then the other non-related directories and all their files will show up as untracked changes. – jewbix.cube Mar 29 '22 at 22:57
-
Folks might be landing here after the master -> main switch on GitHub. If so use `git pull origin main` instead as the last step. – Heiki Jul 05 '23 at 09:24
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.

- 726
- 6
- 13
-
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 Oct 29 '14 at 04:49
-
-
4This is the same answer, just using anonymous https instead of git-protocol over ssh (requiring a github account with an ssh keypair set up). – Peter Cordes Jun 14 '17 at 23:22
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.

- 6,735
- 1
- 29
- 39
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 .

- 101
- 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

- 2,925
- 4
- 26
- 37