27

I forked a private repository that I was invited to collaborate on but every time I try to clone with HTTPS, I get the following error message:

$ git clone https://github.com/usernamex/privat-repo.git
cloning into 'privat-repo'...
Username for 'https://github.com':usernamex
Password for 'https://usernamex@github.com':
remote: Repository not found.
fatal: repository 'https://github.com/usernamex/privat-repo.git/' not found

Note: 'usernamex' and 'privat-repo' are just examples


Here's some things I have tried with no success:

  • Verified the validity of the URL - Checked spelling and case. I am able to access the repo URL and download its contents through my browser by clicking the download ZIP button.
  • Asked owner to clone my fork - He had no problems cloning my fork but I do.
  • Contacted GitHub support...
  • Per GitHub support, cleared cached credentials - this is confirmed by the fact that the system requires my username and password with git clone and git push. In fact, I can clone and push other (public) repositories in my account.
  • Went through GitHub's HTTPS Cloning Errors guide with the exception of "Using SSH instead" because this doesn't really address the issue.
  • Viewed similar questions in stackoverflow.com - tried most suggested answers (see above).

I am running git 2.10 on a mac through Terminal and, as I mentioned, I am not interested in workarounds to HTTPS (e.g.: SSH or GitHub Desktop).

Any ideas why this is happening?

shaleshock
  • 405
  • 1
  • 4
  • 7

10 Answers10

55

This Github document reads:

The https:// clone URLs are available on all repositories, public and private.

But since you are trying to access a private repository, authentication is required. One way is appending username and password the address as below:

git clone https://username:password@github.com/usernamex/privat-repo.git

But the same page reads:

If you have enabled two-factor authentication, or if you are accessing an organization that uses SAML single sign-on (SSO), you must authenticate with a personal access token instead of your username and password for GitHub.

If you have 2FA enabled, check this page for steps to generate a personal access token. Bear in mind that you should check full repo scope (as shown below) for your personal token.

enter image description here

Pejman
  • 1,328
  • 1
  • 18
  • 26
  • 1
    I tried this and one other variation (i.e.: git clone https://usernamex@github.com/usernamex/privat-repo.git) which prompts you for password but the error persists. – shaleshock Feb 24 '17 at 18:33
  • Do you have two factor authentication enabled? – Pejman Feb 24 '17 at 18:34
  • I do, and I know 2FA requires entering a personal access token in place of the password which I entered both manually and through cached methods. At some point I even disabled 2FA and tried with the regular password but that did not help. – shaleshock Feb 24 '17 at 18:40
  • 2
    Does your token have full access scope to your repositories? – Pejman Feb 24 '17 at 18:53
  • 5
    That's it! Token had access to "public_repo" only. I updated the token and it cloned. Thank you! – shaleshock Feb 24 '17 at 19:05
  • 1
    If you are using two factor authorization then just use SSH option for cloning your repository. It will look like 'git clone git@github.com:your-repository-here.git' – Olegdater Apr 01 '18 at 04:13
  • 1
    Your answer saved me, thanks! I had tried every other option I could find or knew of, then realized after seeing this I hadn't checked any options when creating a new token. – SexxLuthor Nov 06 '19 at 22:37
  • 1
    note that PAT (Personal Access Token) can also be used without 2FA enabled – Ham Jun 14 '21 at 06:42
1

With https, you need to create a personal access token (PAT) and use this token as your password every time. Do not use your Github password for 2FA.

But, since doing this is illogical, the easiest way is to use ssh and not https

Generate your ssh token and add it to your account per Github documentation https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent Then, clone the repo locally,

git clone git@github.com:USERNAME/REPO.git

Please make sure to also update your .git/config file to match this ssh url

[remote "origin"]
        url = git@github.com:USERNAME/REPO.git
        fetch = +refs/heads/*:refs/remotes/origin/*
guest
  • 2,185
  • 3
  • 23
  • 46
1

For me, I was accessing private repo and I had to generate a Personal Acess Token.

Then do this : $ git clone -b https://PAT:PAT@github.com/private-repo/repo.git

PAT is Personal Acess Token

0

If you are trying to clone a repository from an account other than the one that you are being authorized for (if it is someone else's repo) and it is coming from an https url, change the https:// in the section of your clone command to http://. Bash will automatically change the request back to https and like magic, the repo will clone successfully. I had this issue on windows (via the mingw64 git bash terminal/cli that comes with git Windows installations.) I tried cloning via https url and kept getting this response:

$ fatal: repository 'https://github.com/random-user/random-repo.git/' not found

I tried all of the above suggestions, and nothing worked. Eventually, I tried removing the 's' from the url, and I got the following response:

$ git clone http://github.com/random-user/random-repo.git Cloning into 'RomanianCoderExamples'... warning: redirecting to https://github.com/random-user/random-repo.git/ remote: Enumerating objects: 175, done.

Btw the above links were added automatically and almost certainly do not work. If they do, someone really needs to rethink their naming scheme

Nate T
  • 727
  • 5
  • 21
0

One should also look into this if the given URL is correct, it might be related to some git credentials already saved on the system:

Git - remote: Repository not found

Sudeep Sagar
  • 141
  • 1
  • 5
0

While this may not apply to your specific instance - this may help out another person who ran into this same issue.

Double check where you are currently located in terminal. If you have been poking around setting up and deleting files prior to attempting your clone operation, it is possible you may have accidentally moved your current location directory to the trash. Terminal will not immediately reveal this information, however if you jump up one level in the file hierarchy (via the 'cd ..' command) then you may see that you are suddenly located in '.Trash'

The solution in this case would be to navigate back to a clean working folder and retry the git clone command.

0

None of the above worked for me. What did was I created a personal access token. When I was prompted for the username I pasted in the token and for the password, I pasted in the token and then only it cloned the repo and voila!.

remote: Enumerating objects: 10642, done.
remote: Total 10642 (delta 0), reused 0 (delta 0), pack-reused 10642
Receiving objects: 100% (10642/10642), 510.06 MiB | 993.00 KiB/s, done.
Resolving deltas: 100% (7509/7509), done.
Updating files: 100% (2324/2324), done

Prior to that, I was getting this error message:

remote: Repository not found.
fatal: repository 'https://github.com/workrepo/repository_I_needed.git/' not found
jeranio
  • 53
  • 8
0

I was also experiencing some issues with github credentials today, since it appears the user/pass authentication has been deprecated:

Support for password authentication was removed on August 13, 2021. Please use a personal access token instead. remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.

I ended up adding a new SSH key for github authentication. And, important notes:


Don't use HTTPS to clone:

git clone https://github.com/USERNAME/REPO.git

Instead use SSH to clone:

git clone git@github.com:USERNAME/REPO.git

Don't use HTTPS as your upstream in .git/config

[remote "origin"]
    url = https://github.com/USERNAME/REPO.git

Instead use SSH as your upstream in .git/config

[remote "origin"]
    url = git@github.com:USERNAME/REPO.git
0

Make sure you have seleted proper scope while geenrating Personal Access Token, this saved my time!

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 24 '21 at 06:53
0

If you can access the repository via your browser, but failed with the git clone command, there is a possibility that you are using a proxy tool which converted the correct url to a wrong ip address, i.e., the hosts problem or DNS problem.

Try to ping github.com or nslookup github.com and see whether they return the expected ip address.

vainquit
  • 491
  • 6
  • 13