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