How to Check If a Branch Has Been Merged into Master? Last Updated : 21 Jun, 2024 Comments Improve Suggest changes Like Article Like Report When working with Git, it's common to create and merge branches as part of your development workflow. However, it's essential to ensure that your branches are merged into the main branch (often master or main) to keep the codebase up-to-date and avoid redundant work. This article will explore several methods to determine if a branch has already been merged into the master branch. Table of Content Why Check if a Branch Has Been Merged?Approach 1: Using git branch --mergedApproach 2: Using git logApproach 3: Using git merge-baseApproach 4: Using Git hosting services (like GitHub or GitLab)Why Check if a Branch Has Been Merged?Avoid Redundancy: Ensure that work is not duplicated and that branches do not contain changes already integrated into the master branch.Maintain Code Integrity: Keep the master branch clean and up-to-date with all relevant changes.Facilitate Collaboration: Help team members know the status of branches and avoid conflicts.Approach 1: Using git branch --mergedStep 1: First Checkout into the master branch using the command, git checkout masterStep 2: Use the git branch --merged command to list all branches that have been merged into the current branch. git branch --mergedIf your branch present in the list then the branch is successfully merged into master.Approach 2: Using git logStep 1: First Checkout into master branch using the command, git checkout masterStep 2: Use the git log command to see if commits from your branch are in the master branch's history. git logIf commits from your branch appear in the log then the branch has been merged into master.Approach 3: Using git merge-baseStep 1: Use the git merge-base command to find the common ancestor of the two branches. git merge-base master your-branch-nameStep 2: Use the git rev-parse command to get the SHA of the branch tip. git rev-parse your-branch-nameIf the output of two commands is same, then branch has been successfully merged into master.Approach 4: Using Git hosting services (like GitHub or GitLab)Go to the Git hosting service you are using, In the section Pull Requests(GitHub) or Merge Requests(GitLab) check the status of your Merge or Pull Request. If the status is merged then the branch has been merged into Master. Comment More infoAdvertise with us Next Article How To Get Changes From Master Into a Branch in Git? A ashokpemeram Follow Improve Article Tags : Web Technologies Git Similar Reads How to Merge a Git Branch into Master? If you're working with Git, merging branches is a fundamental task. Whether you're adding new features, fixing bugs, or improving documentation, merging ensures that your changes are integrated into the main codebase. In this guide, we'll walk you through the process of merging a Git branch into the 3 min read How To Get Changes From Master Into a Branch in Git? In Git, branches are essential for organizing and managing development work. Whether you are working on a feature, a bug fix, or any other task, you often work in a separate branch so that the changes donât directly affect the master or main branch (the primary production branch).There are two main 3 min read How To Get Changes From Master Into a Branch in Git? In Git, branches are essential for organizing and managing development work. Whether you are working on a feature, a bug fix, or any other task, you often work in a separate branch so that the changes donât directly affect the master or main branch (the primary production branch).There are two main 3 min read How to Make the Current Git Branch a Master Branch? Managing branches effectively is a key part of using Git for version control. Occasionally, you might find yourself in a situation where the current branch you're working on should be the new master branch. This could be due to the current branch evolving to become the main line of development, or s 3 min read How to Replace Master Branch with Another Branch in GIT? In Git, the "master" branch traditionally serves as the primary development branch in many repositories. However, there are situations where you might want to replace the contents of the "master" branch with those of another branch. This could be due to a variety of reasons, such as renaming the def 2 min read How to Delete all Git Branches which have been Merged? To delete Git branches that have been merged into the current branch, you can use a combination of git branch and git branch -d commands along with some scripting. Below is a step-by-step guide: Table of Content Switch to the Branch You Want to Clean UpList Merged BranchesDelete Merged BranchesForce 3 min read Like