Let's Learn About Merging The Git Branches 📥📤 And Create Pull Request In Details

Introduction

 
In my previous article, we have discussed about steps to create branch in local git repo and how to push this new branch with commit changes from local git repo to GitHub.
 
Also we discussed the relationship between branches. 
 
In this article, I will describe the below-mentioned points in detail.
  1. Know about merging code from one branch to another branch
  2. Steps for merging git branches
  3. Steps to create pull request
  4. Perform merging using GitHub and Git Bash
  5. Check log history of branches using GitHub and Git Bash
  6. Difference between merging process Using GitHub and Git Bash
Note
Before going through this session, please visit my below-mentioned session related to Git and GitHub.
  1. Introduction To Git
  2. Steps For Configuring Git With Details
  3. Let's Know About Git Add, Git Commit, Git Status And Git Push In Details
  4. Let's Understand How Git Maintains History Of Version Or Commit Ids With Details
  5. Steps To Initialize A Git Repository And Push The Changes To GitHub In Details
  6. Let's Know About Git Branches And How To Implement It
  7. Let's Understand About Git Branches And Its Real Time Uses

What Is Merging Between Git Branches

 
The merging process is moving the changes to file contents from one branch to another branch. This process can be done using 2 ways as mentioned below.
  1. GitHub
  2. Git Bash 

Steps For Merging Git Branches

 
Here I will make changes in MyFile.cs under main branch of SatyaTwo repository as shown below. In my previous article i have mentioned details about SatyaTwo repo and under this repo the available branches are there. Under these branches how to modify these files I already have described.
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Then I will make changes in MyFile2.cs under main branch as shown below.
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Now we check the total no. of commit under main branch along with the commit description are given during Commit changes of above files under main branch as shown below.
 
Here we got total 10 commits.
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Let's compare these total no. of commits of same files under Testing branch of SatyaTwo repo as shown below. Here we got total 5 commits.
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Now I want these commit changes that is 6th, 7th, 8th, 9th and 10th of MyFile.cs and MyFile2.cs files from main branch to the same MyFile.cs and MyFile2.cs files of Testing branch. For this I want to create a new pull request as shown below.
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Now we can see an interface as shown below. That tells us from which branch to which branch you want merge the changes. So, as per the requirements I want to move the changes from main branch to Testing branch as shown below. 
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
So, there is no issue for merging. If there is any issue then we get a merge conflicts issue that means same file has been modified in both the branches. So as of now for me it works fine for merging between branches. Here I have written one message is Merging from main to Testing branch as shown below. Then click on Create pull request.
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Here you get an interface as shown below after creating pull request.
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Then using same interface as mentioned above I click on Merge pull request button as shown below and then it asks for Confirm merge.
 
PIC 1
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
PIC 2
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Now we can see an interface for successful merging between branches as shown below.
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Here I got the pull request URL as shown below.
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Now compare the no. of commits between branches are main and Testing as shown below.
 
No. of commits of main branch
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
No. of commits of Testing branch
 
Here you get the number of pull request messages shown in Testing branch from main branch. I have created one pull request. So, that it shows message like Merge pull request #1 from satyaCsgithub/main.
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Here it shows total no. of commits is 11 because the merging between git branches also a commit. So, that it shows total 11 commits. Check the image as shown below.
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Now we check the updated content of MyFile.cs and MyFile2.cs under Testing branch as shown below. These file contents should be the same as under the main branch.
 
Check Commit messages
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Check new properties added in MyFile.cs
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Check new properties added in MyFile2.cs
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Check the contents under branches in local using git command
 
First let me clone this SatyaTwo repository to my local as shown below.
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Now create directory to this SatyaTwo repository and check the files in this local repo under main branch as shown below.
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Check new properties added in MyFile.cs under main branch,
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Check new properties added in MyFile2.cs under main branch,
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Check the files in this local repo under Testing branch as shown below. 
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Check new properties added in MyFile.cs under Testing branch,
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Check new properties added in MyFile2.cs under Testing branch,
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Now I am connected to main branch and modify the MyFile2.cs file as shown below.
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Now add these changes to staging area. Then commit these changes to local git and finally push these changes to GitHub repository as shown below.
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Then commit and push these changes as shown below.
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
After refresh the GitHub repository under main branch, We can see 11 commits witg commit messages as shown below.
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Now check the content of MyFile2.cs in GitHub repository as shown below.
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Now I switch to Testing branch in local using Git Bash as shown below. Then I will merge the main branch changes to Testing branch.
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Then we get one interface for giving merge description as here default merge message is given as Merge branch 'main' into Testing and save changes. So,for save changes I put one key combination like :wq. Here :wq means that we want to save and quit the file. 
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
After successful merged the changes from main branch to Testing branch then we get the details as shown below. 
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Now check list of files and new modification in MyFile2.cs under Testing branch as shown below.
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Now I have to push the changes to GitHub repository to reflect the same in MyFile2.cs under Testing branch as shown below.
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Now go to GitHub repository and check the MyFile2.cs contents under Testing branch as shown below.
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
Let's check total commits between branches after new changes as shown below.
 
For main branch,
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
After merge from main to Testing branch using Git Bash,
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
It shows total 13 commits because the merge process using Git Bash is itself another commit.
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 

Check Log History Of Git Branches

 
For main branch using Git Bash,
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
For main branch using GitHub repo,
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
For Testing branch using Git Bash,
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
For Testing branch using GitHub repo,
 
Let's Know About Merging The Git Branches 📥📤 And Create Pull Request In Details
 
In this way we can check log history for each and every git branches with commmit IDs and commit messages as shown above.
 

Difference Between Merging Process Using GitHub And Git Bash

  1. Using GitHub we need to create pull request for merging code between main and Testing branch.
  2. Using Git Bash we don't need to create pull request for merging code between main an Testing branch. For this we use command called git merge 'branch name' e.g. git merge main.

Summary


In this write-up, we have learned the below details,
  • Know about merging code from one branch to another branch
  • Steps for merging git branches
  • Steps to create pull request
  • Perform merging using GitHub and Git Bash
  • Check log history of branches using GitHub and Git Bash
  • Difference between merging process Using GitHub and Git Bash
Thank You & Stay Tuned For More