Skip to content

Instantly share code, notes, and snippets.

@chriswburke
Forked from salcode/bash-script-git.sh
Created August 11, 2016 23:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriswburke/2c25c620dcb9f62e3c2d6a320cdcc803 to your computer and use it in GitHub Desktop.
Save chriswburke/2c25c620dcb9f62e3c2d6a320cdcc803 to your computer and use it in GitHub Desktop.
Notes for bash scripting git commands
# 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