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 {repo1}
hg pull {repo2}
hg push -f {repo1}
hg push -f {repo2}
This will result in two heads in both repos (I know it's not common to have two heads, but I'm doing this for synchornisation and it needs to be non-interactive. The heads will be merged manually from one of the repos and then the sync run again).
I'd like to do the same thing in Git. Eg., with no user interaction, get all of the changes into both repos, with multiple branches/heads/whatever to be merged later. I'm trying to do this using urls in the commands, rather than adding remotes(?), as there could be a number of repos involved, and having aliases for them all will just make my script more complicated.
I'm currently cloning the repo using git clone --bar {repo1}
however I'm struggling to "update" it. I've tried get fetch {repo1}
but that doesn't seem to pull my changes down; git log
still doesn't show the changeset that has been added in repo1.
I also tried using --mirror
in my push
and clone
, but that seemed to remote changesets from repo2 that didn't exist locally, whereas I need to keep changes from both repos :/
What's the best way to do this?
Edit: To make it a little clearer what I'm trying to do...
I have two repositories (eg. BitBucket and GitHub) and want people to be able to push to either (ultimately, one will be Git, one will be Mercurial, but let's assume they're both Git for now to simplify things). I need to be able to run a script that will "sync" the two repos in a way that they both contain both sets of changes, and may require merging manually later.
Eventually, this means I can just interact with one of the repos (eg. the Mercurial one), and my script will periodically pull in Git changes which I can merge in, and then they'll be pushed back.
In Mercurial this is trivial! I just pull from both repos, and push with -f/--force
to allow pushing multiple heads. Then anybody can clone one of the repos, merge the heads, and push back. I want to know how to do the closest similar thing in Git. It must be 100% non-interactive, and must keep both repos in a state that the process can be repeated infinitely (that means no rewriting history/changing changesets etc).