Git ошибка 401

I am getting the error

Total 4 (delta 2), reused 0 (delta 0)
error: RPC failed; result=22, HTTP code = 401

When pushing to a git repository on GitLab.

It used to work.

gcbenison's user avatar

gcbenison

11.7k4 gold badges44 silver badges82 bronze badges

asked Jun 18, 2013 at 12:47

Alex's user avatar

I had the same issue: public repos don’t force git to authenticate on the first request, and git doesn’t offer authentication (at least as of version 1.7.9) on subsequent requests of the same push.

This pull request for GitLab should fix it; tested on GitLab 6.3 but it may apply fine on older versions too (please let me know if it fails along with the version string).

https://github.com/gitlabhq/gitlabhq/pull/5760

answered Dec 4, 2013 at 23:28

Thomas Guyot-Sionnest's user avatar

1

After some debugging I realized that I recently activated «Public clone access» on the project. The remote URL is an http:// URL.

Error 401 simply means «access denied» — so even the account is stored in my system, git tries to push without account information which causes this error.

answered Jun 18, 2013 at 12:47

Alex's user avatar

AlexAlex

32.7k17 gold badges107 silver badges172 bronze badges

I am getting the error

Total 4 (delta 2), reused 0 (delta 0)
error: RPC failed; result=22, HTTP code = 401

When pushing to a git repository on GitLab.

It used to work.

gcbenison's user avatar

gcbenison

11.7k4 gold badges44 silver badges82 bronze badges

asked Jun 18, 2013 at 12:47

Alex's user avatar

I had the same issue: public repos don’t force git to authenticate on the first request, and git doesn’t offer authentication (at least as of version 1.7.9) on subsequent requests of the same push.

This pull request for GitLab should fix it; tested on GitLab 6.3 but it may apply fine on older versions too (please let me know if it fails along with the version string).

https://github.com/gitlabhq/gitlabhq/pull/5760

answered Dec 4, 2013 at 23:28

Thomas Guyot-Sionnest's user avatar

1

After some debugging I realized that I recently activated «Public clone access» on the project. The remote URL is an http:// URL.

Error 401 simply means «access denied» — so even the account is stored in my system, git tries to push without account information which causes this error.

answered Jun 18, 2013 at 12:47

Alex's user avatar

AlexAlex

32.7k17 gold badges107 silver badges172 bronze badges

If you’re having trouble cloning a repository, check these common errors.

HTTPS cloning errors

There are a few common errors when using HTTPS with Git. These errors usually indicate you have an old version of Git, or you don’t have access to the repository.

Here’s an example of an HTTPS error you might receive:

> error: The requested URL returned error: 401 while accessing
> https://github.com/USER/REPO.git/info/refs?service=git-receive-pack
> fatal: HTTP request failed
> Error: The requested URL returned error: 403 while accessing
> https://github.com/USER/REPO.git/info/refs
> fatal: HTTP request failed
> Error: https://github.com/USER/REPO.git/info/refs not found: did you run git
> update-server-info on the server?

Check your Git version

There’s no minimum Git version necessary to interact with GitHub, but we’ve found version 1.7.10 to be a comfortable stable version that’s available on many platforms. You can always download the latest version on the Git website.

Ensure the remote is correct

The repository you’re trying to fetch must exist on GitHub.com, and the URL is case-sensitive.

You can find the URL of the local repository by opening the command line and
typing git remote -v:

$ git remote -v
# View existing remotes
> origin  https://github.com/ghost/reactivecocoa.git (fetch)
> origin  https://github.com/ghost/reactivecocoa.git (push)

$ git remote set-url origin https://github.com/ghost/ReactiveCocoa.git
# Change the 'origin' remote's URL

$ git remote -v
# Verify new remote URL
> origin  https://github.com/ghost/ReactiveCocoa.git (fetch)
> origin  https://github.com/ghost/ReactiveCocoa.git (push)

Alternatively, you can change the URL through our
GitHub Desktop application.

Provide an access token

To access GitHub, you must authenticate with a personal access token instead of your password. For more information, see «Managing your personal access tokens.»

If you are accessing an organization that uses SAML SSO and you are using a personal access token (classic), you must also authorize your personal access token to access the organization before you authenticate. For more information, see «About authentication with SAML single sign-on» and «Authorizing a personal access token for use with SAML single sign-on.»

Check your permissions

When prompted for a username and password, make sure you use an account that has access to the repository.

Tip: If you don’t want to enter your credentials every time you interact with the remote repository, you can turn on credential caching. If you are already using credential caching, please make sure that your computer has the correct credentials cached. Incorrect or out of date credentials will cause authentication to fail.

Use SSH instead

If you’ve previously set up SSH keys, you can use the SSH clone URL instead of HTTPS. For more information, see «About remote repositories.»

Error: Repository not found

If you see this error when cloning a repository, it means that the repository does not exist or you do not have permission to access it. There are a few solutions to this error, depending on the cause.

Check your spelling

Typos happen, and repository names are case-sensitive. If you try to clone git@github.com:user/repo.git, but the repository is really named User/Repo you will receive this error.

To avoid this error, when cloning, always copy and paste the clone URL from the repository’s page. For more information, see «Cloning a repository.»

To update the remote on an existing repository, see «Managing remote repositories».

Checking your permissions

If you are trying to clone a private repository but do not have permission to view the repository, you will receive this error.

Make sure that you have access to the repository in one of these ways:

  • The owner of the repository
  • A collaborator on the repository
  • A member of a team that has access to the repository (if the repository belongs to an organization)

Check your SSH access

In rare circumstances, you may not have the proper SSH access to a repository.

You should ensure that the SSH key you are using is attached to your personal account on GitHub. You can check this by typing
the following into the command line:

$ ssh -T git@github.com
> Hi USERNAME! You've successfully authenticated, but GitHub does not
> provide shell access.

If the repository belongs to an organization and you’re using an SSH key generated by an OAuth app, OAuth app access may have been restricted by an organization owner. For more information, see «About OAuth app access restrictions.»

For more information, see Adding a new SSH key to your GitHub account.

Check that the repository really exists

If all else fails, make sure that the repository really exists on GitHub.com!
If you’re trying to push to a repository that doesn’t exist, you’ll get this error.

Error: Remote HEAD refers to nonexistent ref, unable to checkout

This error occurs if the default branch of a repository has been deleted on GitHub.com.

Detecting this error is simple; Git will warn you when you try to clone the repository:

$ git clone https://github.com/USER/REPO.git
# Clone a repo
> Cloning into 'repo'...
> remote: Counting objects: 66179, done.
> remote: Compressing objects: 100% (15587/15587), done.
> remote: Total 66179 (delta 46985), reused 65596 (delta 46402)
> Receiving objects: 100% (66179/66179), 51.66 MiB | 667 KiB/s, done.
> Resolving deltas: 100% (46985/46985), done.
> warning: remote HEAD refers to nonexistent ref, unable to checkout.

To fix the error, you’ll need to be an administrator of the repository on GitHub.com.
You’ll want to change the default branch of the repository.

After that, you can get a list of all the available branches from the command line:

$ git branch -a
# Lists ALL the branches
>   remotes/origin/awesome
>   remotes/origin/more-work
>   remotes/origin/new-main

Then, you can just switch to your new branch:

$ git checkout new-main
# Create and checkout a tracking branch
> Branch new-main set up to track remote branch new-main from origin.
> Switched to a new branch 'new-main'

When cloning a Git repository over HTTPS, you may encounter a 401 error indicating that Git could not authenticate the request. This error can occur if the repository requires a username and password, or if the credentials are incorrect. In some cases, Git may not prompt you for the credentials, leading to frustration and difficulty resolving the issue. This article provides several methods for resolving the Git clone over HTTPS 401 error and for successfully cloning the repository without encountering authentication errors.

Method 1: Check repository URL

To fix the 401 Unauthorized error when cloning a Git repository over HTTPS without being prompted for a username or password, you can try checking the repository URL. Here are the steps:

  1. Open the terminal or command prompt and navigate to the directory where you want to clone the repository.

  2. Type the following command to check the repository URL:

    git config --get remote.origin.url

    This will display the current repository URL, which should start with https://.

  3. If the URL is incorrect or outdated, you can update it using the following command:

    git remote set-url origin https://github.com/USERNAME/REPOSITORY.git

    Replace USERNAME with your GitHub username and REPOSITORY with the name of the repository you want to clone.

  4. Try cloning the repository again using the updated URL:

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

    This should prompt you for your GitHub username and password, and then clone the repository successfully.

Here is an example of the commands in action:

$ cd /path/to/directory
$ git config --get remote.origin.url
https://github.com/oldusername/oldrepository.git
$ git remote set-url origin https://github.com/newusername/newrepository.git
$ git clone https://github.com/newusername/newrepository.git
Username for 'https://github.com': newusername
Password for 'https://newusername@github.com':
Cloning into 'newrepository'...
remote: Enumerating objects: 100, done.
remote: Counting objects: 100% (100/100), done.
remote: Compressing objects: 100% (80/80), done.
remote: Total 100 (delta 25), reused 92 (delta 19), pack-reused 0
Receiving objects: 100% (100/100), 5.03 KiB | 2.52 MiB/s, done.
Resolving deltas: 100% (25/25), done.

That’s it! By checking and updating the repository URL, you should be able to clone the Git repository over HTTPS without encountering the 401 Unauthorized error.

Method 2: Update credentials

To fix the git clone over https 401 error and avoid entering the username and password repeatedly, you can use the credential.helper configuration to store your credentials. The credential.helper will cache your credentials and use them automatically when you interact with the remote repository.

To update your credentials, follow the below steps:

  1. Open the terminal and navigate to the local repository directory.

  2. Run the following command to set the credential.helper configuration:

git config credential.helper store
  1. Run the following command to clone the repository:
git clone https://github.com/username/repo.git
  1. Enter your username and password when prompted.

  2. Run the following command to check if your credentials are stored:

git config --list | grep credential
  1. If you see credential.helper=store in the output, your credentials are stored.

Now, you can interact with the remote repository without entering your username and password repeatedly.

Note: The store credential helper stores your credentials in a plain text file on your disk. If you want to use a more secure method, you can use a different credential helper like cache or osxkeychain.

I hope this helps you to fix the git clone over https 401 error and avoid entering the username and password repeatedly by updating the credentials.

Method 3: Use SSH instead of HTTPS

To fix the «Git clone over https 401 error and not asking for username or password» issue, you can use SSH instead of HTTPS. Here are the steps to do it:

  1. Generate an SSH key pair by running the following command in your terminal:

    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  2. Add the SSH key to your GitHub account by copying the public key to your clipboard:

    pbcopy < ~/.ssh/id_rsa.pub

    Then, go to your GitHub account settings, click on «SSH and GPG keys», and click «New SSH key». Paste the public key into the «Key» field and click «Add SSH key».

  3. Change the remote URL of your Git repository to use SSH instead of HTTPS:

    git remote set-url origin git@github.com:username/repo.git

    Replace «username» with your GitHub username and «repo» with the name of your repository.

  4. Test the connection by running the following command:

    You should see a message that says «Hi username! You’ve successfully authenticated, but GitHub does not provide shell access.»

That’s it! You should now be able to clone your Git repository over SSH without getting a 401 error or being prompted for a username or password.

Method 4: Configure Git to remember credentials

To fix the git clone over https 401 error and not asking for username or password, you can configure Git to remember your credentials. Here are the steps:

  1. Open your Git Bash terminal.

  2. Run the following command to enable credential caching:

git config --global credential.helper cache
  1. Run the following command to set the cache timeout (in seconds):
git config --global credential.helper 'cache --timeout=3600'

This will cache your credentials for one hour.

  1. Clone the repository using the HTTPS URL:
git clone https://github.com/username/repo.git
  1. Git will prompt you for your username and password. Enter them and Git will remember them for the cache timeout period.

Now you can work with the repository without having to enter your credentials every time.

If you want to clear the cached credentials, you can run the following command:

git credential-cache exit

This will clear the cache and you will be prompted for your credentials again the next time you interact with the repository.

That’s it! With these simple steps, you can configure Git to remember your credentials and avoid the 401 error when cloning over HTTPS.

Method 5: Disable SSL verification

To fix the git clone over https 401 error and not asking for username or password, you can disable SSL verification. Here are the steps:

  1. Open the Git Bash terminal.

  2. Type the following command to disable SSL verification:

git config --global http.sslVerify false
  1. Now, try to clone the repository again using the git clone command.
git clone https://github.com/username/repository.git
  1. If you encounter any SSL errors, you can try using the -c option to bypass SSL verification.
git -c http.sslVerify=false clone https://github.com/username/repository.git
  1. If you want to enable SSL verification again, you can use the following command:
git config --global http.sslVerify true

That’s it! You should now be able to clone the repository without any issues.

  • Remove From My Forums

 locked

Git — can not push to remote server — (401) Unauthorized

  • Question

  • Hi,

    im using Visual Studio 2015 (Update 3).

    I try to use the Git commands in the Team Explorer tab. The commit works fine on my local repository but a push to the remote server (my own) fails with following error:

    Error encountered while pushing to the remote repository: An error occurred while sending the request.

    Inner Exception:    The remote server returned an error: (401) Unauthorized.

       Inner Exception:        No credentials are available in the security package

    fetch raises the same exception.

    With cmd, bash or SourceTree i can do all i want.

    i hope someone can help.

    regards, Daniel

    • Edited by

      Wednesday, January 25, 2017 1:45 PM

Понравилась статья? Поделить с друзьями:
  • Git push ошибка 403
  • Git ошибка 128
  • Git push ошибка авторизации
  • Git push u origin master выдает ошибку
  • Git push u origin main ошибка