Keeping remote repository in sync through a rebase
Question
I have a situation where I will have to rebase a topic branch to a master. That's fine, it's the normal rebase case and works great.
The complication is when I'm trying to get this process to be in sync on a bare remote repository.
e.g.
o--o--o origin/master \ o--o origin/topic o--o--o clone/master - tracking origin/master \ o--o clone/topic - tracking origin/topic
Now I make a commit to clone/master which I push to origin/master, so far so good.
o--o--o--n origin/master \ o--o origin/topic o--o--o--n clone/master - tracking origin/master \ o--o clone/topic - tracking origin/topic
This is where I want to end up:
o--o--o--n origin/master \ o--o origin/topic o--o--o--n clone/master - tracking origin/master \ o--o clone/topic - tracking origin/topic
I just can't seem to get there, please help.
The workflow is:
- Clone the bare remote origin
- Make changes to clone/master
- Push changes to origin/master
- Rebase clone/topic to either origin or clone master - doesn't seem to make too much difference
- Now I want the origin/topic to reflect the rebase so I want to push but first I have to pull to make clone/topic fast forward then I end up a merge which has all the original commits from clone/topic with all the commits from origin/topic on top.
Solution
I would modify slightly workflow that you have in order to avoid push --mirror.
- git clone /path/to/origin # clones the master
- git checkout --track origin/topic
- git checkout master
- git add some_new_file; git commit -m "added some new file"
- git push origin/master
- git checkout topic #Local branch
- git rebase master
- git push origin master #it will update master on origin
- git push --force origin/topic : it will update topic on origin
You need --force because origin/topic will change the ancestor and you have disable fast forward check.
OTHER TIPS
Apparently the answer is to push with the --mirror flag. So now the workflow is:
- git clone /path/to/origin # clones the master
- git checkout --track origin/topic
- git checkout master
- git add some_new_file; git commit -m "added some new file"
- git push origin/master
- git checkout topic #Local branch
- git rebase master
- git push --mirror origin #This is the step I had wrong, just a regular push is not good enough
Also note that I'm not sharing the remote repo with anyone but myself otherwise rebasing wouldn't be fair to the other developers.