Git is pretty straightforward until we start working with others.
Like you see, it doesn't take long for the git history to start confusing when multiple people are involved. The common scenario we encounter is
merge conflicts , which means your changes to the target branch is conflicting. Without resolving it, you cannot merge it. So let's see how to resolve the them with an example.
You start working on your branch
feature off the master. If someone updated master while you are working on your branch, master and your branch will start diverging. When it's time to put your change to master, you have to figure out which changes you should take. To do so, follow the steps
- Identify the conflicting parts
git status. If there are any conflicts, this command will say
Unmerged path. If you open up those, you can see something similar to this.
<<<<<<< HEAD // this is some content to mess with a := b fmt.Println("test") ======= // totally different content to merge later a := c >>>>>>> Master
=== is the divider between current branch and master in this example.
Think well and decide which parts to take
You want to take either part of it. Or you want to take little bit of each part and combine them together. Situation can vary. So judge based on your context.
Now remove symbols
<<< , >>>, ===and commit
Once you determine which parts to take, the rest is simple. Let's say you want to take your current implementation, then delete parts down
===to avoid merge conflicts. The last step is to commit change with the meaningful message.
You are good to go! You can do this quickly if you know - which branch you are taking clearly. For example, if you you want to take all changes from master, you can simply run
git merge -X theirs master. Be careful about the relative term
theirs. The opposite is
git merge -X ours master.