Clone A Private Repository (Github)
Solution 1
Private clone URLs take the form [email protected]:username/repo.git
- perhaps you needed to use git@
rather than git://
?
git://
URLs are read only, and it looks like private repos do not allow this form of access.
Solution 2
This worked for me:
git clone https://[email protected]/username/repo_name
Solution 3
I have met this issue several times and every time I landed on this page, tried every thing and failed!
It's because I have 2FA enabled!!!
According to https://help.github.com/articles/which-remote-url-should-i-use/#when-2fa-is-enabled
If you have enabled two-factor authentication, or if you are accessing an organization that uses SAML single sign-on, you must provide a personal access token instead of entering your password for HTTPS Git.
- Follow this link and create an access token
-
git clone https://github.com/username/repo_name.git
(The default git repo link is good enough!) - Enter your username and use the access token as password!!
Update:
- If you don't mind exposing your access token in the command line, you can also paste the access token as username then hit enter enter (no need for password).
- Hate copy&pasting the access token over and over again?
Usegit config credential.helper store
(don't do this on machine you don't trust)
Solution 4
This worked for me:
git clone https://username:[email protected]/username/repo_name.git
Solution 5
Apr, 2022 Update:
You can clone a private repository from your account and you can also clone a private repository from organization if you're its owner or member.
*pat is PAT(Personal Access Token).
git clone https://<pat>@github.com/<your account or organization>/<repo>.git
To clone a private repository from your account or organization, you need to generate a PAT(Personal Access Token) on your Github account, and add it to the command above. *Organization doesn't have PAT generator.
This is how you generate a PAT on your Github account:
1, Go to "Settings":
2, Scroll down then go to "Developer settings":
3, Press "Personal access tokens" then press "Generate new token":
4, Fill "Note" then check "repo":
*If "repo" is not checked, you cannot clone a private repository.
5, Scroll down then press "Generate token":
6, Finally, a PAT is generated:
This is the command with the PAT generated above:
git clone https://[email protected]/<your account or organization>/<repo>.git
Solomon
Updated on July 15, 2022Comments
-
Solomon almost 2 years
I have a private repository on Github for a project I'm working on. Until now I had only worked on my home desktop, but I just bought a laptop, and am trying to set it up so that I can work on the project from either computer, and push / pull changes.
I added a new SSH key to my Github account for the laptop, and was successful in cloning and making changes to a public test repo that I set up. However, I couldn't clone the private repo. Is there anything special I need to do in the command line in order to clone a private repo? Do I need to set up a new GitHub account for my laptop and set myself up as a collaborator?
The command I used was
git clone git://github.com/username/reponame.git
-
Félix Adriyel Gagnon-Grenier over 8 yearsI agree with simplicity of not having to setup ssh
-
reinhardt about 8 yearsthanks for this. But I'm oblivious as to why this works. Was never prompted for a password. Should git clone via https in any way touch my ssh keys? I thought not.
-
The Onin almost 8 yearsNice, it made me able to download a private repo on Ubuntu.
-
greg_data over 7 yearsAgree with other comments, just using HTTPS url works perfect on Windows or Ubuntu (tried on 116.04)
-
diimdeep about 7 yearsWhy this works but [email protected]:username/repo.git don't ?
-
charlchad over 6 years@diimdeep Git and other tools, often use the git: protocol for accessing files in remote repositories. Some firewall configurations are blocking git:// URLs, which leads to errors when trying to clone repositories or download dependencies. (For example corporate firewalls are "notorious" for blocking git:.) If you run into this issue, you can force the use of https: instead, by running the following command: git config --global url."https://".insteadOf git://
-
David Winiecki about 6 yearsIn some cases, if you are prompted for a password and then denied access, it may be because you need to provide a "personal access token" instead of your GitHub login password. [1] help.github.com/articles/which-remote-url-should-i-use [2] help.github.com/articles/…
-
pcnate almost 6 yearsthis is problematic with special character passwords, leaves your password in the logs and doesn't seem to work anymore
-
pcnate almost 6 yearslooks like git prompts for username/password if there is no public repository with that URI, so the first command is correct
-
Pavel Šimerda almost 6 yearsThe answer is wrong, SSH key has no relevance to HTTP access.
-
Let Me Tink About It over 5 yearsThe dollar symbol
$
is a reserved character in Unix. It marks the beginning of the retrieval of a variable value with that name equal to the string that follows the$
symbol. -
leo over 5 yearsYes - using "[email protected]:" rather than "https://" solved my problem! Actually I enabled 2FA at the same time but that had nothing to do with it.
-
Vinay about 5 yearsTry this - You will be prompted to enter your account password. No worries of password learking to history or logs.
git clone https://[email protected]/username/repo_name.git
-
bvdb over 4 yearsIt displays:
unknown option -T
. My git version is2.7.4
-
Kexin Lu over 4 years@bvdb my apologies, it should have been
ssh -T [email protected]
-
Jirik over 4 yearsIf you are on Windows you can install github.com/microsoft/Git-Credential-Manager-for-Windows Then when cloning a private repository, UI window with Github login appear. It will also let you fill 2FA code. Your Github credentials will be stored securely.
-
Michael Larionov over 4 yearsFor me deleting Windows Credentials fixed the problem.
-
Tian almost 4 yearsThis is not safe. The cloned repo stores the provided http link in the .git/config file. All commits made to the local repo can be pushed to remote without requiring username and password. Which is really dangerous if you are not the only user!!
-
Raghu over 3 yearsIn 2FA method at step #4, where is the host mentioned in clone command ?
-
Black Mamba over 3 yearsYes, where
https://[email protected]
is the repository you're trying to clone and the settings are available in your own user settings. -
Farhan Hai Khan over 3 yearsWell if it worked for me in GOOGLE COLABORATORY!
-
Alvin Novian over 3 yearsThank you for this, another way is to set the url format like this:
https://username:[email protected]/username/repo_name.git
it's helpful for me if I have public repo that changed to private. All I need to do is to change the remote origin with that format. -
Muneeb Ahmad Khurram about 3 yearsgood, answer works well in
google colab
just, change ur password before sharing the.ipynb
file :) -
dylanvanw almost 3 yearsAuthentication using passwords will be depreciated on August 13, 2021 and will no longer work after that. github.blog/…
-
Milliron X almost 3 yearsThis will still work if you use a Personal Access Token, and can easily be scripted to prompt for a token (
read -s
). -
teoman over 2 years
git clone https://[USER]:[TOKEN]@github.com/username/repo.git
also works! -
fred over 2 yearsThis apparently has changed slightly.
git clone https://user:[email protected]/username/repo.git
worked for me -
bytefish almost 2 yearsWorks for me in 2022.