How to fix merge conflict in Pull Request
Reference
Create Pull Request
Create a repository called pullrequest-conflict
Then create a file called cat.txt
and paste the following content,
1. In terms of development, the first year of a cat’s life is equal to the first 15 years of a human life. After its second year, a cat is 25 in human years. And after that, each year of a cat’s life is equal to about 7 human years.
2. Cats can rotate their ears 180 degrees.
3. The hearing of the average cat is at least five times keener than that of a human adult.
4. In the largest cat breed, the average male weighs approximately 20 pounds.
5. Domestic cats spend about 70 percent of the day sleeping. And 15 percent of the day grooming.
Create a new branch called feature
Change the angle to 150
in second line of cat.txt in feature
branch
Assume, one more Developer has updated the angle to 200
in cat.txt raised the pull request and merged to master
branch.
Lets create this scenario, go to github, change the branch to master
edit the cat.txt
file and change the angle from 180
to 200
and commit the changes from Github UI
Now create a pull request from feature
to master
branch and you will see merge conflict
Click on Pull Requests
tab and then click on compare & pull request
Github clearly showing, it has conflict and it cannot merge automatically
This is because, we have updated angle to 150 in cat.txt in feature
branch, similary one more developer has updated the angle to 200 in in cat.txt in master
branch and pushed the changes to github.
While we are creating the pull request, git executes the dry-run to merge the line no 2 from remote cat.txt in feature
branch to cat.txt file in master
branch , but it is not able to merge, because cat.txt in master
branch also has new changes(200).
Lets complete the pull request creation and then we will fix the conflict.
Click on Create pull request
To fix the conflict, clone the repository to local system, switch to feature
branch
git clone https://github.com/vigneshsweekaran/pullrequest-conflict.git
cd pullrequest-conflict
git checkout feature
Be clear, currently we are in feature
branch.
Pull the changes from master
to fix the conflict
git pull origin master
We are trying to take the latest changes from master
branch, so that we can clearly merge the feature
branch to master
branch.
It has conflict, so automatic merge has failed.
Update the cat.txt according to your need, I want to keep angle as 150
Add and commit the Fix.
git add .
git commit
Check the commit logs,
git log
Lets push the latest commit to feature
branch,
git push origin feature
Go to Github click on Pull requests
tab. Click on created pull request.
Now we can see, the lastest push to feature
branch has been updated here and conflict has been fixed now.
Click on Merge pull request
–> Confirm merge
to merge the feature
branch with master
branch
How to fix pull request conflict from Github UI itself
Create a new pull request with merge conflict and Click on Resolve conflicts
Fix the conflict and click on Mark as resolved
Click on Commit merge
Click on Merge pull request
–> Confirm merge