git clone or push stops with an HTTP 302 redirect error
error: RPC failed; HTTP 302 curl 22 The requested URL returned error: 302Short 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.
Fix it fast
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)'2Match what you see, then jump to its fix
- 1
The 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
The 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
- 1
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 origin2Fix
Point the remote at the address the server redirects to.
git remote set-url origin https://example.com/team/new-name.git3Verify
Fetch again. It should finish with no redirect error.
git fetch originConfirmed by git-scm.com
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.followRedirects2Fix
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 true3Verify
Run the command that failed.
git pullConfirmed by git-scm.com
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 fixServers
Ansible hangs, then times out waiting for the sudo prompt
a playbook using become seems to hang
Ansible ran sudo on the target and never saw the answer it expected.
3 causes, each with a fixServers
Apache on Ubuntu returns 404 Not Found for my site
The requested URL was not found on this server.
On Ubuntu a 404 from Apache usually means the request maps to a path that has no file.
3 causes, each with a fixServers
Apache returns 504 Gateway Timeout when PHP takes too long
Quick requests work, slow ones end in a 504 after a fixed wait
A 504 from Apache means the backend did not answer within the proxy timeout.
2 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fixServers
Apache warns that a ${VAR} config variable is not defined
${VAR} left unchanged in the configuration, with a warning in the error log
Apache expands ${VAR} from Define or from the shell environment that exists when the server starts.
3 causes, each with a fix