Multiple Remotes

Updated

October 30, 2026

Understanding Multiple Remotes

After this page you can push the same desk-api history to two places.

Extra remotes are normal

cd ~/desk/desk-api
git remote add origin git@forgejo.home:ada/desk-api.git
git remote add github git@github.com:ada/desk-api.git
git remote -v

Fetch both:

git fetch --all
git branch -r

origin/main and github/main are separate photographs.

                    git push origin
                 ┌──────────────────►  Forgejo
 laptop desk-api ┤
                 └──────────────────►  GitHub
                    git push github

 refs/remotes/origin/main
 refs/remotes/github/main

Push to both

git push origin main
git push github main

A convenience:

git remote add all git@forgejo.home:ada/desk-api.git
git remote set-url --add --push all git@forgejo.home:ada/desk-api.git
git remote set-url --add --push all git@github.com:ada/desk-api.git
git push all main

One git push all updates both push URLs. Fetch still uses the first URL of that remote unless you add more fetch URLs. Many people just type two pushes.

Independence preview

Chapter 22 is lock-in. The Git-level move is this page: the objects live in every clone. Two remotes means a forge outage does not strand desk-api. Issues and CI still live on each forge; Git history does not.

Rename and remove

git remote rename origin forgejo
git remote remove github

Removing a remote deletes remote-tracking refs for it. Local branches stay.

origin on a USB disk

git init --bare /media/ada/stick/desk-api.git
git remote add stick /media/ada/stick/desk-api.git
git push -u stick main

Linux mounts the stick; Git sees a path. Same protocol family as ~/desk/desk-api.git.