Git: Get Ahead/Behind Commit Messages in Git Status

Date: 2016-07-25 |

DISCLOSURE: If you buy through affiliate links, I may earn a small commission. (disclosures)

**Problem: **I’m using Git to version control my project. Currently, ‘git status’ returns the number of commits ahead and behind I am for origin/master. However, I want git status to return the number of commits ahead and behind I am for a different branch. How do I do this?

**Solution: **With git 1.8 and later, the syntax is as follows:

While on the branch you’d like to track the difference between, run:

git branch –set-upstream-to remotename/branchname

Now when you run git status, you’ll see the ahead/behind commit differences for the new branch you just set.

Sources

Want more like this?

The best way to support my work is to like / comment / share for the algorithm and subscribe for future updates.