Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

git clone or push stops with an HTTP 302 redirect error

Errorerror: RPC failed; HTTP 302 curl 22 The requested URL returned error: 302

Short answer

Git treats a redirect on a follow-up request as a failure. By default it follows redirects only on the first request to a remote. Find where the URL redirects to, point the remote at that final address, and only if that is not possible set http.followRedirects to true.

  • Applies to Git 2.43, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask the remote URL where it really lives. The Location header in the reply is the address git should be using.

    git remote get-url origin
    curl -sI "$(git remote get-url origin)/info/refs?service=git-upload-pack" | grep -i -E '^(HTTP|location)'
  2. 2Match what you see, then jump to its fix

    1. 1The curl command above prints a 301 or 302 with a Location line pointing somewhere else.The remote URL is old and the server redirects itFix
    2. 2The redirect is expected (a load balancer or reverse proxy in front of the git server) and you cannot change the URL.Redirects are switched off or limited in git's configurationFix

What does the error look like?

  • error: RPC failed; HTTP 302 curl 22 The requested URL returned error: 302

Cause 1 of 2

The remote URL is old and the server redirects it

1Check

Git follows a redirect only for the first request and then uses the new address for the rest. A redirect on a later request is not followed. Compare the URL stored in the repository with the Location value.

git remote get-url origin

2Fix

Point the remote at the address the server redirects to.

git remote set-url origin https://example.com/team/new-name.git

3Verify

Fetch again. It should finish with no redirect error.

git fetch origin

Confirmed by git-scm.com

Did this fix it?

Cause 2 of 2

Redirects are switched off or limited in git's configuration

1Check

http.followRedirects accepts true, false or initial, and initial is the default. With false, every redirect is an error. Read what your machine has set.

git config --show-origin --get-all http.followRedirects

2Fix

Allow git to follow every redirect for that remote only, or remove a global false setting.

git config --global --unset http.followRedirects
git config http.followRedirects true

3Verify

Run the command that failed.

git pull

Confirmed by git-scm.com

Did this fix it?

How do I stop it coming back?

  • Update the remote URL as soon as a repository is renamed or moved, instead of relying on the old address.
  • Keep followRedirects at its default and enable true only for the one repository that needs it.
  • After a server move, check each remote with git remote get-url before the first push.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Servers

dnf cannot install MySQL on Amazon Linux 2023

dnf cannot find a mysql-server package on Amazon Linux 2023

Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.