Tired of having to manually enter the git commands to get latest again and again, I added this script to my .zshrc file in VSCode to handle the process for me.
gitLatest()
{
git status
echo "This action will overwrite any uncommitted changes. Are you sure? (y/n): "
read -e overwrite
if [[ "$overwrite" == "y" ]] ; then
git checkout main
git fetch
git reset --hard origin/main
fi
}
When I run the script, the directions are displayed and I enter “y” at the prompt. The “y” is re-printed and the script terminates.
I’ve tried reformatting the if statement portion a number of ways according to blog posts and SO posts that seemed tangibly related to get the logic to trigger but no action so far gets into the if statement.