Pergunta

I have a local branch which I've pushed to a remote branch. Now I want to merge this branch to the remote master but I'm worried that when I merge it, I might overwrite the changes my teams made. So what is the proper way of merging when you're in a team? I've read about rebase, but I'm not sure how to do it.

Foi útil?

Solução

There isn't really a "proper way". There are best practice and you should be discussing that with your team.

That being said, my favorite way is to delete the (temporary) remote branch and rebase the commits on top of the master branch (typically named "master"):

   git pull # refresh local repo
   git checkout my_branch # go back to my pushed version of my branch
   # make sure that this "my_branch" is the right one!
   git rebase -i origin/their_branch # probably origin/master
   # > fixe conflicts. Test. Reread. Retest. Compare with original my_branch
   # make sure this is really what I want because when I
   git checkout their_branch ; git rebase my_branch ; git push
   # there is no going back.

This updates the "their_branch" as if you had made the changes straight "there" in the first place. All what's left to do is remove the remote branch with:

   git push origin :my_branch

which removes repo reference you your old my_branch which will eventually be garbage collected. The main disadvantage of that approach is the change in SHA1 in the new (rebased) sub tree of commits. But I much prefer that over a merged tree. Hence the best practice discussion you should have with your co-worker.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top