Roman Imankulov

Roman Imankulov

Full-stack Python web developer from Porto

search results (esc to close)

Git

table of contents

Delete merged branches

Leftovers from merged branches are distracting. Too many of them make commands like git branch -l useless. Here are some commands to clean them up.

Get the list of all branches that have been merged into the current branch.

git branch --merged

Delete all branches that have been merged into the current branch.

  • We exclude asterisk because that’s how we identify the current branch.
  • git_main_branch is an Oh My Zsh function that returns the name of the main branch.
git branch --merged  "$(git_main_branch)" | grep -v "$(git_main_branch)" | grep -v '*' | xargs -n 1 git branch -d

See if there is anything left among unmerged branches.

git branch --no-merged

Then delete them one by one.

git branch -D <branch_name>

Delete the refs to branches that don’t exist anymore.

git remote prune origin
Roman Imankulov

Hey, I am Roman, and you can hire me.

I am a full-stack Python web developer who loves helping startups and small teams turn their ideas into products.

More about me and my skills