What git branch was I just in?

My workflow often consists of the following:

  • working on a long term feature branch (call it ‘A’)
  • checking out master and making a hotfix branch (call it ‘B’)
  • pushing my hotfix
  • Then I forget what branch I was working on before that…

Is there any sort of git history that will show me that the thing I was previously working on was branch A?

  • How can I deploy ASP.NET (mvc) site using GIT and for ex. beanstalkapp.com via FTP?
  • How to recover file after `git rm abc.c`?
  • Merge using EGit results in commit of all changes as done by the merger
  • Push to heroku through Proxy server
  • Best practices for using git with CVS
  • Correct way to compare same file in different branches
  • How to change default branch when using arc diff?
  • Way to modify git pack files?
  • Keep changes while doing a `git stash`
  • Git (SSH) in Visual Studio 2015
  • How do I rename a git remote?
  • 'git submodule update --init --recursive' VS 'git submodule foreach --recursive git submodule update --init'
  • 4 Solutions collect form web for “What git branch was I just in?”


    git reflog

    which will list all of your recent actions that changed something, so checkout, rebase, pull, push, etc.

    Also it includes all the commit ids, so for example if you did a dozen commit --amend you can jump back to one in the middle.

    As documented in gitrevisions, the syntax @{-number} refers to the branch checked out number occurrences ago. This uses the reflogs, specifically the reflog for HEAD; see Duncan’s answer.

    (In your particular example you’d want @{-1}. For git checkout you can abbreviate this as git checkout -, but that only works for git checkout.)


    git branch --sort=-committerdate


    git for-each-ref --sort=-committerdate refs/heads/
    git checkout -

    go to the the previously used branch

    I’ve also set this alias that prints the last 10 branches I’ve worked on :

        recent = for-each-ref --count=10 --sort=-committerdate refs/heads/ --format='%(refname:short) %(committerdate:relative)'
    Git Baby is a git and github fan, let's start git clone.