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:

  1. Clone the bare remote origin
  2. Make changes to clone/master
  3. Push changes to origin/master
  4. Rebase clone/topic to either origin or clone master - doesn't seem to make too much difference
  5. 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.
Was it helpful?

Solution

I would modify slightly workflow that you have in order to avoid push --mirror.

  1. git clone /path/to/origin # clones the master
  2. git checkout --track origin/topic
  3. git checkout master
  4. git add some_new_file; git commit -m "added some new file"
  5. git push origin/master
  6. git checkout topic #Local branch
  7. git rebase master
  8. git push origin master #it will update master on origin
  9. 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:

  1. git clone /path/to/origin # clones the master
  2. git checkout --track origin/topic
  3. git checkout master
  4. git add some_new_file; git commit -m "added some new file"
  5. git push origin/master
  6. git checkout topic #Local branch
  7. git rebase master
  8. 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top