Push to Multiple Git Repos

Andrew
2 min readAug 7, 2020

--

Photo by Yancy Min on Unsplash

Everyone uses Git. I’ve been using Git for a few years but still don’t fully understand its inner workings; I know enough just to get by.

Recently, I found myself looking up how to push to multiple repositories with a single git push command. I wanted to do this because I had a project hosted on a Git repository where I had limited access (it was not GitHub), and I wanted to keep a copy of it in sync on GitHub.

A quick search gave me a command to set this up:

git remote set-url --add --push origin https://github.com/makandre/my-repo-copy.git

The command seems buggy however, because it never quite works the first time I run it. Instead of adding a url to my origin remote, it replaced the old one. Only after I fiddle with it a few times — remove, add, rinse and repeat— did I manage to get what I was after:

git remote -vvorigin https://originhost/somepath/my-repo.git (fetch)
origin https://originhost/somepath/my-repo.git (push)
origin https://github.com/makandre/my-repo-copy.git (push)

Looking at the .git/config file, it added the last 2 lines to the origin remote:

[remote "origin"]
url = https://originhost/somepath/my-repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
pushurl = https://originhost/somepath/my-repo.git
pushurl = https://github.com/makandre/my-repo-copy.git

Next time I need to do this, I will edit the config file directly.

--

--

No responses yet