Search code examples
gitgithubgit-mergegit-commit

What is the correct order of git command I should use?


I have 3 local branches master, A and B. This is a old project, I did not updated the my local repo for a long time.

I made some changes on B, and then git checkout A; git pull master to update my local A branch with remote master. Then I run** git merge B**, resolve the merge conflicts and raise a pull request.

But my colleague tell me that I should do it in this way: first git checkout A; git merge B; git pull master, resolve the conflicts and then raise a pull request. I did not realize any differences. Can anyone help me out?


Solution

  • Both methods are correct and will give you the right result if done correctly. But, you have to choose the easier way to do it.

    Your colleague seems to think that it will be easier for you to merge your old branch B into your old branch A first. Then merge the changes from the remote master once into your A branch.

    If you do it your way, you will have to resolve conflicts with the master twice: first when you merge it into your old A branch and then when you merge your old B branch with the changes that were in both the A and master.

    Only you can decide which option is easier for you as it depends on the nature and number of changes in each branch.