Here comes part 5, in the previous four blog posts we had discussed git installation, how to create a repository, how the .git folder works, how to push files, git branch, and many more. If you haven’t read the basic theory part then I strongly recommended you to read the first four-part and then start practicing.
Click here for GitHub Part1 , GitHub Part2 , GitHub Part3 and GitHub Part4
What is git merge command?
1) Member 1 has created several branches and, also did multiple commits.
2) All the task is perfect.
3) Member 1 wants to bring the result to the main branch.
4) then after all the changes will be available to other team members.
5) To do this, we have to use the “git merge” command. It helps us to join the branches together.
How do I merge local branch and local master in GitHub?
git branch new-update-one git switch new-update-one
Do some changes to your files. Like, add a new line of code.
git status git add testToday.txt git commit -m "Hello msg added" git log
Git log: – To see the changes we had done. And your head pointer points to the new branch we just create.
Do some changes again in your file but from the MAIN branch.
git switch main git add . git commit -m "new form changes - done"
1) First commit: – Your newly created branch
2) Second commit: – is using our main branch.
Make sure that you are on the main branch.
git merge new-update-one -m "Merge new-update-one to main" git log --oneline
What is merge conflict in GitHub?
In the real world, this scenario happens most of the time when two developers tried to change the same line of code. Let’s understand with an example. ( Page Name:- Index.html)
Both the developer has updated the file in line number 3.
Git can’t understand which version of code is the latest one. Git can not merge it automatically. Here comes the merge conflict. So, the conflict should be resolved manually.
Member 2 has to pull all the latest changes into his branch, check where exactly the merge conflicts happen, and change it.
After the merge conflict issue is resolved the file can be merged to the master branch.
git switch -c desi-changes
Create new file style.css
Using Git Bash you can create a new file using the command or manually in your editor create a CSS file.
How do I create a new file in Git Bash?
git add .
The step which I have specified in the image below, I have already covered in my previous blog post. If you are confused about it (how the command works) then please read all the previous posts.
Developer 2 came into the picture.
git switch main
- New Js file and set the path.
Up to point 4, you know how the flow works.
Still, I can create the pull request, so on the same page click on the “Create Pull Request” button.
After I click on the button, I see the merge button gets disabled.
Let’s resolve the conflict.
Open the page in any editor.
Here you can see the different symbols get added to the index.html.
Head is the pointer to the place where you are currently in your working directory.
Incoming changes: – Changes from the master branch that merged after implementation of the task. Let’s manually adjust the code.
It is time to do the commit.
git status git add . git status git commit
We can see that we successfully merged the changes.
It is time to update our remote branch.
Refresh your GitHub pull request page.
I can merge with creating a new commit.