Push Git repository to multiple providers
February 12, 2022
Summary
Disclaimer
This article assumes that you’re using version 1.8 (October 2012) or later of Git
Creating a Git remote
You can skip this step if you already have one
To create a remote, follow the example below:
git remote add <name> <url>
# example
git remote add origin git@git.sr.ht:~henriquehbr/some-random-repository
Adding Git providers
Now we’ll add the destinations to where we want to push updates of our repository, in order to do that, follow the example below:
git remote set-url <name> --push --add <url>
# example
git remote set-url origin --push --add https://github.com/henriquehbr/some-random-repository
Note that some Git providers (such as sourcehut) might treat
https://
URL’s as read-only, and prevent you from pushing commits when setting apush
URL with them
Setting a default remote
You can skip this step if you already have a default remote
git push --set-upstream <remote-name> <branch>
# example
git push --set-upstream origin main
Special thanks
- To ELLIOTTCABLE for his insightful answer on StackOverflow