Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clone A Private Repository (Github)

People also ask

Can I clone a private GitHub repository?

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.

Can anyone clone a private repo?

You also have the option to clone a private GitHub repository using SSH. To do this, you need to start by generating an SSH keypair on your local device. Then add a public key to your GitHub account. This gives you the ability to connect your local device with GibHub using a secure channel over an unsecured network.


This worked for me:

git clone https://[email protected]/username/repo_name


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.


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.

  1. Follow this link and create an access token
  2. git clone https://github.com/username/repo_name.git (The default git repo link is good enough!)
  3. 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?
    Use git config credential.helper store (don't do this on machine you don't trust)

This worked for me:

git clone https://username:[email protected]/username/repo_name.git

For me the solution was:

git clone https://[email protected]

Here you need to be the owner of the repo but if you aren't then it will go as

git clone https://[email protected]/ownersusername/repo_name.git

If you have 2FA enabled then:

  1. Go to the settings from the profile icon in top right or visit https://github.com/settings/profile
  2. Go to the bottom tab or go to https://github.com/settings/tokens
  3. Open last tab here Personal tokens. And generate a token
  4. Copy the token and run git clone https://[email protected]

When prompted for password put that token in here. Token generation image here


Using Git for Windows it is easier to use HTTPS url.

Open a git shell then git clone https://github.com/user/repo. Enter username and password when prompted. No need to setup a SSH key.


As everyone aware about the process of cloning, I would like to add few more things here. Don't worry about special character or writing "@" as "%40" see character encoding

$ git clone https://username:[email protected]/user/repo   

This line can do the job

  1. Suppose if I have a password containing special character ( I don't know what to replace for '@' in my password)
  2. What if I want to use other temporary password other than my original password

To solve this issue I encourage to use GitHub Developer option to generate Access token. I believe Access token is secure and you wont find any special character.

creating-a-personal-access-token

Now I will write the below code to access my repository.

$ git clone https://username:[email protected]/user/repo

I am just replacing my original password with Access-token, Now I am not worried if some one see my access credential , I can regenerate the token when ever I feel.

Make sure you have checked repo Full control of private repositories here is the snap short