brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: git remote set-url points your clone at a moved repository

Git
~/tips/tip-git-remote-set-url

git remote set-url origin [email protected]:owner/new-name.git

Changes where origin points after a rename, a move or a switch to SSH.

Repositories get renamed, move to another account or to another host. Your clone keeps the old address until you change it, and there’s a command for that.

git remote -v
git remote set-url origin [email protected]:owner/new-name.git
git remote -v

The first line shows the current fetch and push address of each remote. set-url replaces the address of origin for both, and the last line confirms it. Branches, tracking and everything else stay as they are.

It’s also how I’d switch an existing clone from HTTPS to SSH, which is just a different address for the same repository.

There’s a less known variant for different push and fetch addresses:

git remote set-url --push origin [email protected]:owner/mirror.git

After this, git fetch still uses the original address while git push goes to the other one. It’s a way to push to a mirror, but it’s easy to forget it’s there. git remote -v shows both lines, so check it when pushes go somewhere unexpected.

GitHub redirects old addresses after a rename, so a forgotten clone often keeps working for a while. Don’t rely on that: once someone creates a new repository with the old name, the redirect stops and your pushes could land in the wrong place.

Further reading: git-remote documentation, GitHub: renaming a repository

Going deeper: Moving on from hdtv: how to export your TV show list to Trakt.tv

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link