Skip to content

Instantly share code, notes, and snippets.

@4lberto
Last active August 8, 2017 10:37
Show Gist options
  • Save 4lberto/ccb47427ba97d6f50a9a91efdc1e4afc to your computer and use it in GitHub Desktop.
Save 4lberto/ccb47427ba97d6f50a9a91efdc1e4afc to your computer and use it in GitHub Desktop.
Git tricks
#In a repo, returns a list of the numbers of commites per file ordered desc
git rev-list --objects --all | awk '$2' | sort -k2 | uniq -cf1 | sort -rn |
while read frequency sample path
do
[ "blob" == "$(git cat-file -t $sample)" ] && echo -e "$frequency\t$path";
done
#search for remote branches with a specific name fo deleting afer
git fetch origin;git remote update origin --prune;git branch -r |grep WORDINNAME
#remove remote branches with the word "WORDINNAME" (use first git branch -r |grep WORDINNAME |sed 's/ origin\///' to be sure)
git fetch origin;git remote update origin --prune;git push origin --delete $(git branch -r |grep WORDINNAME |sed 's/ origin\///')
#Another version with XARGS (works with project manage)
git fetch origin;git remote update origin --prune;git branch -r |grep WORDINNAME |sed 's/ origin\///' |xargs git push origin --delete
#Remove local branches except the current one
git branch --list |grep -v '*' |xargs git branch -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment