Checking local branch is ahead or behind remote branch

To see a local branch is ahead or behind its upstream branch, use:

# List all branches with more information:
# id, message and relationship with their upstream branches
$ git branch -vv
develop 99914fb [origin/develop: ahead 2] fix: missing comma
* master 04a4f6a [origin/master: ahead 1, behind 2] feat: add menu
temp 94f4439 feat: add custom post type
test ac5446a [origin/test] initial commit

Above information illustrates the following relationship with remote ones:

  • develop branch is ahead origin/develop by 2 commits
  • master branch is ahead by 1 commit, and behind by 2 commit
  • temp branch is not tracking any remote branch
  • test branch stays up to date

Note that the remote information may not be up to date, it just present situations the last time you communicated with remote server.

To see up to date information, you can first update changes from remote :

# Fetch update from all remote tracking branches. Note it does not
# merge them to the local branches.
$ git fetch --all
$ git branch -vv