Skip to content

Instantly share code, notes, and snippets.

@DarkOoze
Created May 29, 2024 08:28
Show Gist options
  • Save DarkOoze/b50916141937d0abdfac04c76df2c853 to your computer and use it in GitHub Desktop.
Save DarkOoze/b50916141937d0abdfac04c76df2c853 to your computer and use it in GitHub Desktop.
Git script to reset local changes
#!/usr/bin/env sh
currentFullName=$(git rev-parse --symbolic-full-name HEAD)
branch=$(git rev-parse --abbrev-ref $1)
branchFullName=$(git rev-parse --symbolic-full-name $branch)
upstream=$(git rev-parse --symbolic-full-name $branch@{upstream})
if [ $? -ne 0 ]
then
exit # No tracked branch.
fi
if [ "$currentFullName" = "$branchFullName" ]
then
git reset --soft $upstream
else
git branch -f $branch $upstream
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment