Reputation: 1019
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?
Upvotes: 2
Views: 810
Reputation: 1019
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
Upvotes: 1
Reputation: 8527
A post-receive
hook is a server-side hook, which means it would only make sense to install it on the remote, which in this case is most likely not possible. See here or here, for instance.
One way to achieve what you want would be to use a pre-push
hook instead. In this case, when you push to Azure, the script will first run (before the push), and the push will be attempted only if the script exits with status 0 (i.e., succeeds).
Upvotes: 1