Created
September 5, 2015 19:54
-
-
Save salcode/342391ccbaa8cbf48567 to your computer and use it in GitHub Desktop.
Notes for bash scripting git commands
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
# Current branch - Determine current git branch, store in $currentbranch, and exit if not on a branch | |
if ! currentbranch=$(git symbolic-ref --short -q HEAD) | |
then | |
echo We are not currently on a branch. | |
exit 1 | |
fi | |
# Uncommited Changes - Exit script if there uncommited changes | |
if ! git diff-index --quiet HEAD --; then | |
echo "There are uncommited changes on this repository." | |
exit 1 | |
fi | |
# Remote exists - Exit script if remote does not exist | |
git ls-remote --exit-code ${remote} >/dev/null 2>&1 | |
if [ $? -ne 0 ] | |
then | |
echo "Remote ${remote} does not exist" | |
exit 1 | |
fi | |
# Root path of Repo | |
rootpath=$(git rev-parse --show-toplevel) | |
# Branch exists - Exit script if local branch does not exist | |
git rev-parse -q --verify ${branch} >/dev/null 2>&1 | |
if [ $? -ne 0 ] | |
then | |
echo "Branch ${branch} exists" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, this is great!