eax
(fath|lead|hack)er

Pushing to Multiple Git Repos

Let’s say you have sourcehut as your primary git location, but also want to push that same repo to a github instance without having a mirror setup. What you can do is configure the two additional remotes and push them from there. All one needs is the following:

$ git remote set-url --add --push origin git@git.sr.ht:~USER/REPO.git
$ git remote set-url --add --push github git@github.com:USER/REPO.git

If you take a look at your config file under your .git folder, the added urls will appear under:

[remote "origin"]
    url = git@git.sr.ht:~USER/REPO
    fetch = +refs/heads/*:refs/remotes/origin/*
    pushurl = git@git.sr.ht:~USER/REPO

[remote "github"]
    url = git@github.com:USER/REPO.git
    fetch = +refs/heads/*:refs/remotes/github/*
    pushurl = git@github.com:USER/REPO.git 

The only thing left to do now, is code, commit, push to each of the respective repos and they will be updated. For example:

git push # that will default to pushing to your origin repo
git push github # self-explanatory

You can write a script if you want to automate or not forget pushing to both repos at the same time.

Back to top