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?– bryanbraunMay 14, 2014 at 5:20
-
To actually skip downloading unneeded objects to save network resources: stackoverflow.com/questions/600079/…– Ciro Santilli OurBigBook.comSep 11, 2018 at 7:20
7 Answers
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.
-
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..." May 23, 2013 at 10:58
-
18
-
1@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. May 23, 2016 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.– SelrondMar 22, 2017 at 5: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 Jun 2, 2018 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 [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.
-
Hey in this I am getting an error like Permission denied <public key>. The remote end hung up unexpectedly.– StanFeb 20, 2014 at 7:24
-
Shouldn't it be
github.com
there aftergit remote ...
, and not justgithub
? May 21, 2015 at 21:18 -
6
-
I read elsewhere here that you need to run
git fetch --all
before thegit pull origin master
, because if there are other branches on the repo,git pull
won't get those unless you usefetch
first. Is this correct?– Alex GNov 22, 2018 at 11:22 -
But then the other non-related directories and all their files will show up as untracked changes. Mar 29, 2022 at 22:57
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.
-
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– guribe94Oct 29, 2014 at 4: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). Jun 14, 2017 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.
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 .
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