DEV Community

Brandon Rozek
Brandon Rozek

Posted on • Originally published at brandonrozek.com on

Git Pushing to Multiple Remotes

Git’s greatest strength is its first-class support for decentralization. Sadly, GitHub has taken over as the sole location to store code for many people.

In order to not put all my eggs into one basket, I want to utilize multiple code hosting websites to store my public repositories. This is not only for the GitHub zombie apocolypse scenario, but local outages do in fact happen and its nice to have a backup.

Ideally this backup would not come at a cost of convinience. In fact, we can edit the remotes of our git repository so that a simplegit push updates all of our remotes.

The following is an example from my website. Within your repository, use the command git config -e to open an editor with your repository’s git conifguration. Then edit the origin block to be configured with multiple push-urls.

[remote "origin"]
        url = git@github.com:Brandon-Rozek/website.git 
        fetch = +refs/heads/*:refs/remotes/origin/*
        pushurl = git@github.com:Brandon-Rozek/website.git
        pushurl = git@git.sr.ht:~brandonrozek/website

Enter fullscreen mode Exit fullscreen mode

After this, typing git push every pushurl you have configured. For me, it updates both my GitHub repositoryas well as my SourceHut repository.

I only recently started using SourceHut. It’s designed by Drew Devaultand others to feature the original usage of git, via email. This method is still in use by the Linux kernel development team. I’m excited to try it out and hopefully write some future posts on this concept.

Top comments (0)