🌿 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-nameSafely 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-nameDeletes 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-nameRemoves 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-threeDeletes multiple local branches at once.
Clean up stale remote tracking refs
git fetch --pruneRemoves local references to remote branches that no longer exist.
When to use: After team members delete remote branches and your local refs are stale.