🌿 BranchingCommonly used

How to delete a branch in Git

Remove local and remote branches you no longer need.

Delete a merged local branch
git branch -d branch-name

Safely deletes a local branch. Fails if the branch has unmerged changes.

When to use: After a branch has been merged into main.

Force delete local branch
git branch -D branch-name

Deletes a local branch even if it has unmerged changes.

Deletes unmerged commits. Make sure you no longer need the branch.

Delete a remote branch
git push origin --delete branch-name

Removes the branch from the remote repository.

When to use: After a PR/MR has been merged and the remote branch is no longer needed.

Delete multiple local branches
git branch -d branch-one branch-two branch-three

Deletes multiple local branches at once.

Clean up stale remote tracking refs
git fetch --prune

Removes local references to remote branches that no longer exist.

When to use: After team members delete remote branches and your local refs are stale.

← Back to Git Reference