Skip to content

Instantly share code, notes, and snippets.

@captainsafia
Created February 23, 2017 18:17
Show Gist options
  • Save captainsafia/e8c75c8d9d5558e7a0678df6a3273875 to your computer and use it in GitHub Desktop.
Save captainsafia/e8c75c8d9d5558e7a0678df6a3273875 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