Search code examples
gitgithubgithooksgit-push

How to push changes to another remote after pushing them to origin (upstream)?


I'm using Visual Studio's Git integration to push my changes to https://dev.azure.com. Today I created a GitHub repo, and added my main changes as remote for my GitHub repo with these commands from Visual Studio Git root folder:

git remote add upstream https://github.com/user/repo
git push upstream master

Now I have copy of all my changes in GitHub. When I make new changes in Visual Studio and push them to https://dev.azure.com, I'd like those to be pushed to GitHub too. I heard about Git hooks. So I wrote this in post-receive script:

#!/bin/sh
git push upstream master
exit 0

But when I pushed my changes from Visual Studio, my GitHub repo wasn't updated, so I had to do git push upstream master manually.

What am I doing wrong?


Solution

  • To answer my own question, I found this article which clearly explains how to add remotes for simultaneous pushing (with one git push command).

    In short, you can configure multiple remotes for simultaneous pushing this way:

    git remote add all first_remote_url
    git remote set-url --add --push all first_remote_url
    git remote set-url --add --push all second_remote_url
    

    That's it! Now you can push to both remotes with the following one command:

    git push all
    

    BONUS: while you cannot pull from multiple repos, you can do this to fetch information from all remote repos:

    git fetch --all