I\'m writing a Bash script, and I want to checkout a tag and then checkout back to where I started.
I tried git co HEAD@{1}
, but when starting at master, th
In your script, first save the current branch (like written in this answer):
branch_name="$(git symbolic-ref HEAD 2>/dev/null)" ||
branch_name="(unnamed branch)" # detached HEAD
branch_name=${branch_name##refs/heads/}
then go and checkout the tag you want to
git checkout -b tag_branch tag_name
Do what you want to do on that branch, then checkout the old branch again:
git checkout $branch_name
That's it.