Multiple Remotes
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 -vFetch both:
git fetch --all
git branch -rorigin/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 mainA 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 mainOne 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 githubRemoving 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 mainLinux mounts the stick; Git sees a path. Same protocol family as ~/desk/desk-api.git.