1. git

Remove local tracking branch that not exists on remote

When a feature branch finished using git flow then it may still in the local branch on another developer machine.
So to keep updated your local branches with remote branches you need to clean up your local branches that aren’t on the remote.

Follow this to clean up & get synced with the remote origin –

  • To clean up information of local branches with remote. Run –
git fetch --prune
  • Delete branches that aren’t on remote. Run –
git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -d

If you face error like this –
error: The branch my_local_test_branch is not fully merged

Use -D to force the delete for unmerged branches.

git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -D
https://rdevs.xyz
Do you like Ashiqur Rahman's articles? Follow on social!
Comments to: Remove local tracking branch that not exists on remote

Your email address will not be published. Required fields are marked *

Attach images - Only PNG, JPG, JPEG and GIF are supported.

Login

Welcome to rDevs

Brief and amiable onboarding is the first thing a new user sees in the theme.
Join rDevs

start writing