Clone A Private Repository (Github)

Question

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

Answer

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":

enter image description here

2, Scroll down then go to "Developer settings":

enter image description here

3, Press "Personal access tokens" then press "Generate new token":

enter image description here

4, Fill "Note" then check "repo":

*If "repo" is not checked, you cannot clone a private repository.

enter image description here

5, Scroll down then press "Generate token":

enter image description here

6, Finally, a PAT is generated:

enter image description here

This is the command with the PAT generated above:

git clone https://[email protected]/<your account or organization>/<repo>.git

Move branch pointer to different commit without checkout

Cannot determine the organization name for this 'dev.azure.com' remote URL