I have two repository urls, and I want to synchronise them such that they both contain the same thing. In Mercurial, what I\'m trying to do would be:
hg pull
As others I came here because this SO-question has so right header for this particular problem.
This was few years ago. I studied available answers, but nothing solved my situation.
I took a step further and created several solutions.
And my final solution posted here is for Git repositories only (sorry, I do not use Mercurial right now as it was asked in the body of the question).
I had rather difficult conditions at the start than others here.
And just like the author of this SO question, I also wanted to have
I quickly wrote some bash script and quickly realized that with Git this would not be enough.
The main problem is conflict solving.
Long story short, you can only solve conflicts by some conventions or by asking to repeat a conflicting merge (commit).
So, my script became a compiled application.
Later arrived some requirements.
The other thing is that people tend to forget the fact that they have two synchronized remote Git-repositories. They do it really fast and do not want to remember any rules.
Some teams may have some level of employee rotation.
A big application requires more documentation and support. And etc.
Finally, I threw out some complicated conflict solving and state analysis.
A remaining subset of logic was pretty simple, which allowed me to convert my app into a bunch of bash and gAWK scripts.
And as a result of all, my tool only synchronizes branches with defined prefixes.
You can say, let's synchronize branches that begin with the @.
Or branches that start with my-company- and your-company-.
Of course, my tool has a little learning curve.
But it is quite mature and gives a possibility to forget about some sync problems, at all.
Actually I forgot about my tool and came here two years later, because I've implemented a wish list.
My latest tool is here - git-repo-sync. I hope this will help someone else.