Git

How Can I Know if a Branch Has Been Already Merged Into Master

Git users utilize the repository and branches to implement and track changes. More specifically, Git branches are widely used for testing, storing different versions of code, implementing features, and many more. Usually, developers merge two or more branches into one branch to implement changes or to integrate a project into a single branch.

This write-up will illustrate how to know if a branch is already merged into the master.

How to Know if a Branch has been Already Merged Into Master?

Git users are familiar with the master or main branch; these branches are the default branches of Git repositories. To know if a branch is already merged into the master, first, open the Git repository and try to merge the branch. As a result, either the “Already up to date” message will appear, which means the branch is already merged into the master. You can also view a graph to view branches merged into the master.

Step 1: Open Git Terminal

First, open the Git terminal from the Start menu:

Step 2: Open Git Repository

Next, utilize the “cd” command to move to the Git repository:

$ cd "C:\Git\demo1"

Step 3: Merge Branch

Merge the branch into the master branch through the provided command:

$ git merge demo

Utilize the “git merge” command once more to merge the branch again into the master:

$ git merge demo

It can be observed that the “Already up to date” message has been displayed which means that the branch is already merged into the master:

Step 4: Check if the Master is Already Merged

However, to view the branches merged into the master branch, check out the Git logs in the form of the graph:

$ git log --graph

Alternatively, execute the below-mentioned command to view the log in the form of a oneline graph:

$ git log --oneline --graph --all

From the below output, you can see that the “demo” is merged into the master, and the “features” branch is already merged into the master branch:

We have illustrated how to know if a branch is already merged into the master.

Conclusion

To merge any branch into the master, open the master branch and utilize the “git merge <branch name>” command. To know if a branch has already been merged into the master branch, users can view the Git logs in the form of a graph by utilizing the “git log –graph” command or “git log –oneline –graph –all” command. In this article, we have illustrated how to know if a branch is already merged into the master or not.

About the author

Rafia Zafar

I am graduated in computer science. I am a junior technical author here and passionate about Programming and learning new technologies. I have worked in JAVA, HTML 5, CSS3, Bootstrap, and PHP.