Skip to content

Instantly share code, notes, and snippets.

@upkarlidder
Forked from captainsafia/quesadilla.bash
Created February 23, 2017 19:27
Show Gist options
  • Save upkarlidder/130f3f43fc19e8098bc0fc490082ebe9 to your computer and use it in GitHub Desktop.
Save upkarlidder/130f3f43fc19e8098bc0fc490082ebe9 to your computer and use it in GitHub Desktop.
When the user has changed into a git directory, rebase with upstream if there are no uncommitted files.
function cd {
# Run the system CD command on the parameters that were passed in
builtin cd "$@"
# Check if the directory we are in now is a git directory
if [ -d ".git" ]; then
# If so, check to see that there are no uncommitted files
if [ $(git status --porcelain 2>/dev/null| egrep "^(M| M)" | wc -l) ]; then
# Rebase our current branch with upstream/master
git fetch upstream && git rebase upstream/master
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment