Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Git Functions
function diff-branch() {
if [ -z $1 ]; then
echo please provide an branch
read WORKBRANCH
else
WORKBRANCH=$1
fi
if [ -z $2 ]; then
STABLEBRANCH='master'
else
STABLEBRANCH=$2
fi
TMPBRANCH="tmp/$(date +'%Y%m%d/%H%M%S')"
git checkout $WORKBRANCH
git checkout -b $TMPBRANCH
# Load the deltas
git reset --soft $STABLEBRANCH
# Commit the deltas
git commit -m"$WORKBRANCH deltas"
# Delete the old story branch
git branch -D $WORKBRANCH
# Rename the new branch
git branch -m $WORKBRANCH
}
# When run inside of a git repo, prints out all branches that have no remote branch or a deleted remote branch
function no-remote() {
if git rev-parse --git-dir > /dev/null 2>&1; then
git fetch --prune
echo "Branches with no remote:"
git branch -vv | cut -c 3- | awk '$3 !~/\[/ { printf " %s\n", $1 }'
echo -e "\nBranches with deleted remote:"
git branch -vv | awk '$4 ~/gone\]/ { printf " %s\n", $1 }'
else
echo "Not a git repository"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment