Github makes very easy to collaborate with people, however sometime it’s a bit complicated to understand how to use Pull Request, and in particular how to make sure that the feature branch can be merged in master in a Fast Forward way
So let’s se how we can go from this(Or the famous “can’t be merged automatically”)
to this: (Or yeah, this looks good)
Why this happens
The problem is that both in master and in your branch some files have been changed, and their going in different directions. The content of the file in master is different from the one in your feature_branch, and git does not know which one to pick, or how to integrate them.
To solve this, you need to
- Get the latest upstream/master
- Switch to your master
- merge the latest master in your master (Never develop in master, always develop in a feature branch)
- switch to your feature branch
- merge master in your feature branch
- solve all the conflicts: this is where you decide how to integrate the conflicting files, and this can be done only by you because you know what you did, you can figure out what happened in master, and pick the best way to integrate them.
- commit all the changes, after all the conflicts are solved
- push your feature branch to your origin: the Pull Request will automatically update
Talk is cheap, show me the commands (cit. adapted)
If you didn’t already add the upstream to your repo, have a read to this
1. Fetching upstream
git fetch upstream
2. Go to your master. Never develop here.
git checkout master
3. Bringing your master up to speed with latest upstream master
git merge upstream/master
4. Go to the branch you are developing
git checkout my_feature_branch
5. It will not be fast forward
git merge master
6. Solve the conflicts. get a decent 3 views visual diff editor. I like Meld
git mergetool
7. Commit all the changes. Write an intelligible commit message
git commit -m "Decent commit message"
8. This will push the branch up on your repo.
git push origin my_feature_branch
September 10, 2014 at 7:21 am
tnx
September 10, 2014 at 7:24 am
You’re welcome
October 1, 2014 at 5:45 pm
You’re welcome 🙂
March 19, 2015 at 3:06 pm
thnku soooooooooooooooooooo much … means a lot 🙂
March 19, 2015 at 3:06 pm
Tnakzzz a Lottt !!!!!!!!!!!!!
May 28, 2015 at 8:09 pm
Thank You!!
May 28, 2015 at 10:54 pm
You’re welcome!
May 29, 2015 at 10:33 am
You are welcome!
September 16, 2015 at 5:17 pm
Thank you, this helped! Before reading this, I was just rebasing my feature branch with the master of remote. This worked locally (everything showed up-to-date in my terminal) but Github still couldn’t automatically merge my pull-request to remote. Any idea why I specifically need to update master first and then rebase off of it?
September 16, 2015 at 5:47 pm
Glad it helped.
I do not use rebase, so I can’t really say too much about it. sorry!
September 16, 2015 at 7:34 pm
No worries! I submitted a question on SO: http://stackoverflow.com/questions/32616100/git-why-necessary-to-update-master-first
Hopefully somebody will answer it soon.
February 4, 2016 at 10:56 pm
Thanks a lot
February 5, 2016 at 7:12 am
You are welcome!