Adrian Altner

Git: pushing to multiple remotes at once

Auf Deutsch lesen


I self-host my website on a VPS via a bare repository with a post-receive hook and simultaneously mirror the code to Codeberg. With a small Git trick, a single git push is all it takes.

Two push URLs for one remote

Git lets you assign multiple push URLs to a single remote — both targets live under origin instead of as separate remotes. Fetch still runs from one source only, but when pushing, all URLs are used in sequence:

git remote set-url --add --push origin ssh://vps/var/www/myproject.git
git remote set-url --add --push origin ssh://git@codeberg.org/user/repo.git

After that, git remote -v looks like this:

origin  ssh://vps/var/www/myproject.git (fetch)
origin  ssh://vps/var/www/myproject.git (push)
origin  ssh://git@codeberg.org/user/repo.git (push)

From now on, a plain git push is enough:

git push

Git sends the branch to both targets automatically.

Why not two separate remotes?

You could add a second remote called codeberg and always run git push origin && git push codeberg. That works, but it’s easy to forget. With two push URLs on the same remote, mirroring happens implicitly — no extra step, no forgotten remote.

Note:

Optionally, a third URL can be added, for example for GitHub:

git remote set-url --add --push origin git@github.com:user/repo.git

The next git push will then automatically send to all three targets.

Use git remote -v to check how many push URLs are currently set.