Skip to content

Instantly share code, notes, and snippets.

@noherczeg
Created July 10, 2018 09:03
Show Gist options
  • Save noherczeg/38f4e9ab5c456c00613f69ea563d88af to your computer and use it in GitHub Desktop.
Save noherczeg/38f4e9ab5c456c00613f69ea563d88af to your computer and use it in GitHub Desktop.
git branch reset script with optional target branch parameter
#!/bin/bash
if [ $# -eq 0 ]
then
branch=$(git rev-parse --abbrev-ref HEAD)
else
branch=$1
fi
echo "--------------------------------"
echo "Resetting to branch: ${branch}"
echo "--------------------------------"
git clean -fd
git fetch
git checkout $branch
git reset --hard origin/$branch
git pull
echo "--------------------------------"
git status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment