Skip to content

Instantly share code, notes, and snippets.

@TwP
Created April 14, 2009 13:57
Show Gist options
  • Save TwP/95188 to your computer and use it in GitHub Desktop.
Save TwP/95188 to your computer and use it in GitHub Desktop.
# This function returns the name of the current git branch
function gitb {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
# This function updates the current branch with the latest changes from the
# origin repository. The master branch is checked out, a git pull is performed,
# the original branch is checked out again, and then the changes from master
# are rebased back into the branch.
#
# Essentially, the following steps are performed. The command is smart enough
# to do the right thing when the current branch _is_ the master branch.
#
# git checkout master
# git pull --rebase
# git checkout $branch
# git rebase master
#
function gitu {
branch=`gitb`
if [ "$branch" != "master" ]; then
git checkout master
fi
git pull --rebase
if [ "$branch" != "master" ]; then
git checkout "$branch"
git rebase master
fi
}
# This function pushes the changes from the current branch up to the origin
# repository. The master branch is checked out and the changes from the
# original branch are rebased into the master branch. After this, all changes
# are pushed to the origin repository. The original branch is checked out
# again.
#
# Essentially, the following steps are performed. The command is smart enough
# to do the right thing when the current branch _is_ the master branch.
#
# git checkout master
# git rebase $branch
# git push
# git checkout $branch
#
function gitp {
branch=`gitb`
if [ "$branch" != "master" ]; then
git checkout master
git rebase "$branch"
fi
git push
if [ "$branch" != "master" ]; then
git checkout "$branch"
fi
}
# This function calls the "gitu" and the "gitp" functions in succession. This
# pulls in changes from the master branch to the current branch, and then
# pushes all changes from the current branch up to the origin repository. This
# combination of commands keeps the master branch revision history nice and
# linear.
#
function gitup {
gitu
gitp
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment