Skip to content

Instantly share code, notes, and snippets.

@hkraji
Last active December 25, 2017 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hkraji/dee97cd38db70b85c54a5fd04bb47671 to your computer and use it in GitHub Desktop.
Save hkraji/dee97cd38db70b85c54a5fd04bb47671 to your computer and use it in GitHub Desktop.
Bash script to update or checkout needed git branches
#!/usr/bin/env bash
#
# Usage:
#
# checkout BRANCH_NAME
#
# checkout master
# checkout hkraji/pr_work_in_progress
#
git rev-parse --verify $1 > /dev/null 2>&1
if [ $? == 0 ]
then
echo "Branch $1 exists, updating branch ..."
git checkout $1
git pull origin $1
else
echo "Creating branch $1 ..."
git fetch origin $1
git checkout -b $1 origin/$1
fi
# clear nginx cache (optional)
rm -rf /tmp/nginx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment