2

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?

user3132457
  • 789
  • 2
  • 11
  • 29

2 Answers2

1

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).

GoodDeeds
  • 7,956
  • 5
  • 34
  • 61
  • I also tried `pre-push` but I think something was wrong (with Azure?). when I pushed from Visual Studio, the operation got stuck. When I tried `git push` from command line, it was still stuck, so I did Ctrl+C, and some warning/error messages were printed. Anyways, after some research I found an article which explained how to do this (I have posted it as answer). – user3132457 Mar 04 '20 at 07:26
1

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
user3132457
  • 789
  • 2
  • 11
  • 29