Git Dual Remotes




I am using both GitHub and Codeberg for my Git repositories. It is possible to setup multiple push URLs for a given repository. This allows you to interact with both remotes with a single command. Here’s how.

# Set up origin at GitHub
git remote add origin git@github.com:zanshin/repo.git

# Add Codeberg as a second push URL to origin
git remote set-url --add --push origin ssh://git@codeberg.org/zanshin/repo.git
git remote set-url --add --push origin git@github.com:zanshin/repo.git

Once the push URLs are set, running git remote -v will show one remote as the fetch remote and both as push remotes.

origin  git@github.com:zanshin/repo.git (fetch)
origin  git@github.com:zanshin/repo.git (push)
origin  git@codeberg.org/zanshin/repo.git (push)

With this configuration, git pull will only pull from the fetch remote, in the example above, GitHub. git push will push to both remotes.

Using Jujutsu, jj, you can push to all URLs using

jj git push --all-remotes

Using git for repository interactions there may be drift between the remotes, since pulls are only from the fetch remote. Periodic pulls from the other remote will be necessary to stay in sync.

Using Jujutsu, jj, for repository interactions allows you to use

jj git fetch --all-remotes

which will fetch from multiple remotes simultaneously.

The key point is that git pull only uses the fetch URL, while git push uses all push URLs.