Source code control
Git GitBash GitHub

How to use Git to Branch Features and Merge Changes

Welcome to today’s post!

I will give an overview of using branching and merging of feature changes using Git.

When we wish to create a new branch from our master branch, we use the following git command:

git branch -b [feature branch name] 

After making changes to our new feature, we apply the changes to the master branch using the following command:

git commit
git push master

If we have merge conflicts attempting to push our changes to the master branch, then we apply the following command:

git merge [feature branch name]

After running this merge, if you are in GitBash or in VSCode you will see screenful of source files including changes, additions, and deletions downloaded from git into your current project folder for the current branch:

Switch back to VS 2017. You will see the solution folder files change with combined changes merges from the feature branch!

Back inside git bash, run the command:

git status

You will get the following message:

This tells you that you are ahead of the master by 1 commit. Will need to push changes over to the master remote repository?

No.

Why?

The got merge command does an auto-commit after the merge.

If you had run:

git merge [feature branch name] --no-commit –no-ff

then the merge would not be auto-committed and would require an additional git push like the one below:

git push origin master

Now go back to your source repository and check the master folder. The merge from the feature has been applied to the master branch:

That’s all!

Hope you have learned something new today from this post.

To understand more about branching and merging using git, refer to the official documentation from git (https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging).

Social media & sharing icons powered by UltimatelySocial