Last active
March 12, 2024 11:44
-
-
Save higebu/be00886d9ab49c05c39a243c54196f71 to your computer and use it in GitHub Desktop.
git-pull-hard
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
#!/bin/bash | |
current_branch=$(git branch --show-current) | |
tracking_branch=$(git branch -vv | grep ${current_branch} | grep -oP '\[\K[^]]*(?=\])' | cut -d':' -f1) | |
if [ -z "$tracking_branch" ]; then | |
echo "No tracking branch found for ${current_branch}" | |
exit 1 | |
fi | |
remote=$(git remote) | |
branch=$(echo ${tracking_branch} | sed "s/$remote//" | sed "s#/##") | |
git fetch ${remote} ${branch} | |
git reset --hard ${tracking_branch} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment