WebMasterCampus
WEB DEVELOPER Resources

How to Merge Git Branches

How to Merge Git Branches


Merge Git Branches

  • In Git, branches are a part of your daily development process.
  • Git branches are actually a pointer to a snapshot of your changes.
  • When you want to add a new feature or fix a bug—no matter how big or how small it is, you create a new branch to capture your changes.
  • When you fix bug or build new feature than you can easily merge them with git merge command.

Let’s Suppose we are going to build login functionality of our application. We can create a branch “Login” and this branch “Login” will encapsulate all login related in functionality. Once we will be done with login functionality we can easily merge Login to our main or master branch.

You can do following steps:

First, create a Login branch. It will create a new branch based on master branch. So, you will have a copy of master inside login.

Git Create Login Branch

git branch Login

Second checkout the branch you want to update with login functionality in our case “Login”.

Git Checkout Login

git checkout Login

Now we can write our application login functionality. After all code related to login done, we can add and commit code to staging.

Git Commit to Staging

git add .
git commit -m "Login Branch with login functionality"

Finally, We can merge this login to master branch.

To merge Login Branch to master, we need to checkout master and then run the git merge command.

Git Merge

git checkout master

git merge Login

git merge command will create a merge commit that will included the differences between the 2 branches.

Created with love and passion.