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?bryanbraun– bryanbraun2014-05-14 05:20:18 +00:00Commented May 14, 2014 at 5:20
- To actually skip downloading unneeded objects to save network resources: stackoverflow.com/questions/600079/…Ciro Santilli OurBigBook.com– Ciro Santilli OurBigBook.com2018-09-11 07:20:22 +00:00Commented Sep 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.
7 Comments
. 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.rm .DS_Store and you're good to go.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
github.com there after git remote ..., and not just github?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?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
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
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