Skip to content

Instantly share code, notes, and snippets.

@philss
Created June 30, 2015 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philss/4db11bba7092b76d4f3e to your computer and use it in GitHub Desktop.
Save philss/4db11bba7092b76d4f3e to your computer and use it in GitHub Desktop.
Zsh git functions
# Put those functions on your ~/.zshrc or something similar.
# Cleans all merged branches (relative to the branch you are). Recommended to run from master.
function git_clean_branches()
{
# Fetch all merged branches that are not the master branch, and not the current branch
echo 'Deleting all merged branches...'
for branch in `git branch --merged | awk -F ' * ' '{print $2}' | grep -v -e 'master' | grep -v -e '*'`
do
echo "Removing .. $branch"
git branch -d $branch
done
echo 'Done!'
}
# List files that contains a given term
function git_grep_files()
{
git grep $1 | awk -F ':' '{print $1}' | sort | uniq
}
# Replace terms inside files under the same repository.
# Usage git_replace "old_term" "new_term"
function git_replace()
{
original=$1;
new_version=$2;
echo "$original -> $new_version"
echo
for file in `git_grep_files $original`; do
echo "Replacing in $file"
sed -i '' "s/$1/$2/g" $file;
done;
echo;
echo "Done";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment