Maaz Zindani

Loading the index…

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

git clone or fetch dies with: unable to update url base from redirection

Errorfatal: unable to update url base from redirection:

Short answer

Git asked for one URL, got redirected, and the final URL did not end with the same path piece it requested. Git then cannot learn the new base address and stops on purpose. Run a verbose request to see where you land. Use the real repository URL in your remote, or fix the redirect rule on the server.

  • Applies to git 2.45, git 2.50, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Trace the redirect chain Git sees, using the same URL as your remote. The last Location line is where Git ended up.

    git remote -v
    GIT_CURL_VERBOSE=1 git ls-remote 2>&1 | grep -i -E "^< (HTTP|location)"
  2. 2Match what you see, then jump to its fix

    1. 1The redirect line in the error ends in something like /login or a home page, not in the asked-for pathThe server redirects to a page that is not the repositoryFix
    2. 2The redirect line ends in a different host, group or repository nameThe repository moved and the remote still has the old URLFix

What does the error look like?

  • fatal: unable to update url base from redirection:
  • asked for: https://example.com/team/app.git/info/refs?service=git-upload-pack
  • redirect: https://example.com/login

Cause 1 of 2

The server redirects to a page that is not the repository

1Check

Git follows a redirect on the first request only, and uses the final URL as the new base for later requests. To do that it strips the same ending it asked for from the final URL. If the final URL does not end with it, Git gives up. A login page, a captive portal or a proxy rule that sends everything to one page causes exactly that.

curl -sIL "https://example.com/team/app.git/info/refs?service=git-upload-pack" | grep -i -E "^(HTTP|location)"

2Fix

Fix the rule on the server or proxy so the git paths are passed through, or authenticate first so the request is not sent to the login page. Do not work around it by turning redirects off, which makes every redirect an error.

# check what git is configured to do (default is initial)
git config --get http.followRedirects

3Verify

The same curl call now returns 200 or 401 on the git path, not a redirect to a page.

git ls-remote origin

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 2 of 2

The repository moved and the remote still has the old URL

1Check

Compare your remote with the address the server reports. A renamed or transferred repository, or a changed host name, redirects the old path.

git remote get-url origin

2Fix

Point the remote at the new address. Git follows a redirect on the initial request only, so the stored URL should be the final one.

git remote set-url origin https://example.com/new-group/app.git

3Verify

Fetch from the remote with no redirect error.

git fetch origin

Confirmed by git-scm.com

Did this fix it?

How do I stop it coming back?

  • Update remotes after a repository is renamed or moved, instead of relying on the old URL.
  • When you put a proxy in front of a Git server, pass the Git paths through unchanged.
  • Test a new proxy or login rule with git ls-remote before telling the team.

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.