What to do with branch after merge
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
After a branch has been merged, the usual next step is to delete it if it was a short-lived feature or bugfix branch. The merge already preserved the work in the target branch, so keeping the old branch name often adds clutter more than value. The main exceptions are long-lived branches and branches that still serve an active release or maintenance purpose.
The Normal Case: Delete the Merged Branch
In most team workflows, a feature branch exists only to isolate one unit of work. Once that work is merged into main, develop, or another long-lived branch, the branch has finished its job.
Delete the local branch:
Delete the remote branch:
The -d option is the safe version. Git refuses the deletion if it does not believe the branch has been fully merged.
Why Deleting Is Usually Safe
Deleting a branch name does not delete the merged commit history from the repository. The commits remain reachable through the branch that received the merge.
That is the key idea:
- the merge preserved the work
- the feature branch name is only an extra reference
- removing the extra reference does not erase merged code
If feature/login-form was merged into main, the work now lives in main. The old branch pointer is usually redundant.
When You Might Keep the Branch
Some branches are intentionally long-lived and should remain after merges.
Common examples:
- '
main' - '
develop' - release branches
- maintenance or support branches
You might also keep a branch temporarily if:
- post-merge verification is still happening
- more closely related work will continue there immediately
- your team's deployment or release policy depends on that branch existing
The right question is not "was it merged?" but "does this branch still represent an active line of development?"
Local Cleanup After Merge
After the merge, it is usually worth refreshing your local repository state.
git fetch --prune removes stale tracking references for remote branches that no longer exist. That keeps branch listings cleaner.
You can also inspect which local branches are already merged:
That is a useful command when old feature branches have accumulated over time.
Squash Merge and Rebase Merge Nuance
Branch cleanup still makes sense after squash merge or rebase-and-merge, but Git ancestry may look different from a traditional merge commit.
In some squash-merge cases, Git may not consider the local branch "merged" in the usual ancestry sense, so git branch -d can refuse deletion even though the changes are already integrated.
In that case, you may need:
Use -D only when you are certain the branch's changes are safely present in the target branch. It skips Git's safety check.
Remote Hosting Workflow
If your repository is hosted on GitHub, GitLab, or another platform, you may also see a UI option to delete the source branch immediately after merging a pull request. That is usually a good default for short-lived branches.
Even if the platform can delete the remote branch automatically, you may still want to remove the stale local branch later.
That keeps both the remote and local branch lists focused on active work.
What If You Need the Branch Again
If you deleted a merged branch and later want to continue related work, create a new branch from the current target branch.
That is usually better than trying to preserve every old feature branch just in case future work might happen.
Common Pitfalls
- Keeping every merged feature branch forever, which makes the repository noisy and harder to scan.
- Deleting the branch before confirming the correct changes were merged into the intended target branch.
- Forgetting to delete the remote branch after cleaning up only the local one.
- Using
-Dcasually without verifying that the work is already preserved elsewhere. - Treating milestone history as a reason to keep branches forever when tags, merge commits, and pull request history already preserve that information.
Summary
- Short-lived feature and bugfix branches are usually deleted after merge.
- Delete both the local and remote branch when they are no longer needed.
- Deleting a merged branch name does not delete the merged commits.
- Long-lived branches such as release or maintenance branches are different and may stay.
- If future work is needed, create a fresh branch from the current mainline rather than preserving every old feature branch.
Related reading
- What to do with commit made in a detached head
- What to gitignore from the .idea folder?
- What would I use git-worktree for?
- What's the -practical- difference between a Bare and non-Bare repository?
- What's the best visual merge tool for Git?
- What's the correct way to check if it's possible to perform a fast-forward merge with git merge-base?
- What's the difference between commit and apply in SharedPreferences
- What's the difference between git clone --mirror and git clone --bare
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.