How to show log between current branch and its remote counterpart

Viewed 46

Sometimes after fetching from remote repository I see my branch is behind:

> git status
On branch develop
Your branch is behind 'origin/develop' by 7 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

Before updating my local branch I would like to see the log of what I'm about to get. I can do it using

> git log develop..origin/develop

Since I'm already on the develop branch, is there a way to do the above with less typing? That is, without providing local and remote branch names?

This would be especially useful since I often switch to feature branches and would like to see such logs for those, too.

1 Answers

Yes, a short and branch-agnostic way is to use the @{upstream} construct :

git log ..@{u}

(Note : since the first part of the range is omitted here, HEAD is implied, but the full verbose syntax would be HEAD..HEAD@{upstream}.)


And of course it's very handy to have it as alias.behind (for example) since it'll use whatever branch you're on.

Edit after comments : I added the useful counterpart alias.ahead to check commits about to be pushed (there's a catch : while @{upstream} refers to the remote branch where your config will pull from, the branch set in config to push to is @{push} (doc)). In some specific 3-way settings, these may differ, but in most simple workflows both point to the same branch of the same remote. But it's just in case.

git config --global alias.behind 'log [any format option you prefer] ..@{u}'
git config --global alias.ahead 'log [any format option you prefer] @{push}..'
Related