Skip to content

Instantly share code, notes, and snippets.

@eegeeZA
Last active May 6, 2022 08:20
Show Gist options
  • Save eegeeZA/2f680eb9c9372d2d2db839f79ed2cfb9 to your computer and use it in GitHub Desktop.
Save eegeeZA/2f680eb9c9372d2d2db839f79ed2cfb9 to your computer and use it in GitHub Desktop.
Clean up unnecessary local and remote branches
# WIP #
# remove *local* branches merged into origin/master
#&"git" branch -d @(git branch --merged origin/master | Select-String -Pattern "^\*|(develop|master)$" -NotMatch)
# remove *remote* branches merged into origin/master
#&"git" push origin -d @((git branch -r --merged origin/master | Select-String -Pattern ".*(origin/(qa1|qa2|prod)$)" -NotMatch) -Replace " *origin/","")
# remove *local* branches merged into origin/develop
git branch --merged origin/develop | egrep -v "(^\*|(develop|master)$)" | xargs git branch -d
# remove *remote* branches merged into origin/develop
git branch -r --merged origin/develop | egrep -v "(origin/(develop|master)$)" | cut -d "/" -f 2- | xargs git push origin -d
# remove all files that should be ignored
git rm -r --cached . && git add .
# normalise the line endings
git add --renormalize .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment