Last active
August 29, 2015 14:14
-
-
Save philss/3aa5a3522510ecf43059 to your computer and use it in GitHub Desktop.
A collection of shell script functions to work with git.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Returns a list of files with a given term | |
function git_grep_files() { | |
git grep $1 | awk -F ':' '{print $1}' | sort | uniq | |
} | |
# Replace terms inside a git repository | |
# | |
# Example: | |
# git_replace "original_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"; | |
} | |
# Removes all merged branches from you local repository | |
# | |
# Example | |
# git_clean_branches | |
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!' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment