git checkout –

For those familiar with the bash shell, you may know that it has the ability to change directory to the last directory you were in by using the cd - command.

$ cd /var/log/
$ cd /usr/local/bin
$ pwd
/usr/local/bin
$ cd -
/var/log
$ cd -
/usr/local/bin
$

Lo and behold, Git has a similar feature as well, git checkout -. This command will take you back to the last branch/tag/commit you had checked out

$ git status
On branch some_very_long_branch_name
nothing to commit, working directory clean
$ git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
$ git fetch
$ git pull
Already up-to-date.
$ git checkout -
Switched to branch 'some_very_long_branch_name'
$

–Proctor

Leave a Reply

Your email address will not be published. Required fields are marked *