Skip to content

Instantly share code, notes, and snippets.

@higebu
Last active March 12, 2024 11:44
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 higebu/be00886d9ab49c05c39a243c54196f71 to your computer and use it in GitHub Desktop.
Save higebu/be00886d9ab49c05c39a243c54196f71 to your computer and use it in GitHub Desktop.
git-pull-hard
#!/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