15

I have 2 branches - master and develop

I have been doing some pull requests in my develop branch where it contains 5 items, in which it is the same as the number of items in master.

However, someone did some commits and pushed in a few more items into the master branch, and hence now it has 8 items.

As my pull request in the develop is still not yet approved/merged, whenever I tried to update my pull request, I am getting the message stating that This pull request can't be merged. You will need to resolve conflicts to be able to merge and asked me to do the following:

git fetch origin master
git checkout develop 
git merge FETCH_HEAD
git commit
git push origin HEAD

And this happens after I have 'pushed' out my commits, making me confused at times. Then I realized that it is asking me to re-add and re-commit in the additional 3 new items. So does this means I must ensure that the items and contents between these 2 branches of mine should be the same as always? I have always used git pull/fetch but will there be a better way for me to make sure?

dissidia
  • 1,531
  • 3
  • 23
  • 53
  • No, it is asking you to merge. You seem to be confused about how branches work -- see the [related chapter in the docs](http://git-scm.com/book/en/Git-Branching) – remram Sep 29 '14 at 20:31
  • @remram Probably I am indeed confused. But even so, why would it ask me to merge the master onto develop? Usually it is the other way round for me – dissidia Sep 30 '14 at 02:14
  • If you merge master in develop, then github will be able to automatically merge develop in master. – remram Oct 06 '14 at 18:26
  • @remram Hmm, okay.. Still do not get it why I must merge master to develop.. So this means that I need to have the same number of items in both master and develop branch so as to prevent such conflicts in the future? – dissidia Oct 07 '14 at 02:06
  • You don't *need* to do anything. Github will just tell you whether these branches can be merged automatically or not. If they can't, you'll just have to merge the PR from the command-line instead of the website when the time comes, and that's it. – remram Oct 07 '14 at 15:37
  • We call the merge from master back to develop a "back merge". This will synchronize the 2 branches to a point where the changes on develop can be merged up to master. This happens a lot where there are a large number of developers making simultaneous changes to the project. – Richard Jessop Dec 11 '18 at 15:20

1 Answers1

20

What this means is that GitHub would like to merge your PR branch into master, but it can't, because there are conflicts. As you've discussed in the question comments, the best way to deal with this (usually) is to merge your master branch into develop on the command line. That will show you the conflicts and ask you to resolve them. Once you've completed and pushed that merge, the PR will be mergeable back into master using the green button on GitHub.

You could simply merge your deploy branch into master (which I realize sounds a bit more sensible). In that case, you'd be bypassing the PR entirely. You'd have to close the PR "unmerged", and separately you'd manually push the merge commit to master.

By doing it the first way,

  1. you make a better audit trail by merging to master on GitHub, using the PR;
  2. you give your team a chance to review your code after the merge, before it lands on master; and
  3. if you have automatic tests (such as Travis CI or CircleCI) which check PRs, you give them a chance to run your merged code as well.
Peeja
  • 13,683
  • 11
  • 58
  • 77
  • It has sort of making sense to me then, especially in the case of the PR branch, in which it would be totally different from what I have been doing where my `develop` branch is being merged into `master` just like what you have mentioned. – dissidia Oct 08 '14 at 02:35
  • That's right. If you've got a single `develop` branch that periodically merges to `master`, you'd probably do better not to make pull requests from that branch. If you like, you can make pull requests from specific topic branches to `deploy`, and then merge `deploy` to `master` at the command line when you're ready to move a set of changes over. – Peeja Oct 08 '14 at 17:21
  • This link gives a good overview of how to achieve Peeja's statement of merging master into develop: https://confluence.atlassian.com/bitbucket/resolve-merge-conflicts-704414003.html – Paul Jan 26 '17 at 17:14