Created
May 29, 2024 08:28
-
-
Save DarkOoze/b50916141937d0abdfac04c76df2c853 to your computer and use it in GitHub Desktop.
Git script to reset local changes
This file contains hidden or 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
#!/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