Categories
git git-diff git-log

Viewing unpushed Git commits

2129

How can I view any local commits I’ve made, that haven’t yet been pushed to the remote repository? Occasionally, git status will print out that my branch is X commits ahead of origin/master, but not always.

Is this a bug with my install of Git, or am I missing something?

7

  • 24

    Starting with Git 2.5+ (Q2 2015), the actual answer would be git log @{push}... See that new shortcut @{push} (referencing the remote tracking branch you are pushing to) in my answer below

    – VonC

    Jun 8, 2015 at 22:44


  • 79

    @Torek – yet another simple task made difficult by Git. Every time a Git question shows up with hundreds or thousands of upvotes and millions of views, then someone should think: Wow, we really screwed up that workflow. Alas, the Git dev’s have omitted the feedback step in the development life cycle, so the feedback is not incorporated. Instead, they keep making the same mistakes over and over again. For this question, git status --all should have appeared in 2010; or git status -v should actually provide the verbose output that includes the extra information.

    – jww

    Jul 10, 2016 at 19:32


  • 5

    I disagree that “git status -v” should provide this information because it is intended to give status about the working tree, as it relates to the checked out branch only. However, see the answer below about “git branch -v”, which I believe should be the accepted answer

    – JoelFan

    Jan 31, 2017 at 19:38

  • 23

    This particular StackOverflow question has the highest number of correct answers that all work yet don’t make any sense.

    Jan 11, 2018 at 21:20

  • 1

    @jww: I agree. I have moved back to using git after using mercurial. Compared to the ease-of-use and elegance of mercurial, git is an adulterated mess

    – Paul

    Nov 24, 2020 at 14:11

2147

This gives a log of all commits between origin/master and HEAD:

git log origin/master..HEAD

When HEAD is on the master branch, this gives a log of unpushed commits.


Similarly, to view the diff:

git diff origin/master..HEAD

18

  • 4

    This did it for me – for some reason git log origin.. by itself was throwing an error. Looks like I also had a problem with the way my local branch was configured – once I made the changes I found here: wincent.com/blog/… …the problem was resolved, and I could use git status again to see what I wanted.

    Jan 6, 2010 at 22:57

  • 6

    Invaluable: So much so I did git config --global alias.ahead "log origin/master..HEAD --oneline" so that I can quickly find out where I am. Even more candy: for i in *; do echo $i && git ahead 2>/dev/null; done

    – Jamie

    Feb 28, 2012 at 2:50

  • 27

    git log --stat origin/master..HEAD for a little extra awesomeness

    Mar 25, 2013 at 17:51

  • 163

    This is not the best solution. Origin/master may not always the upstream branch. A better solution is to use @{u} instead of “origin/master” to indicate the upstream branch. Since HEAD is implied by default, one can leave that out too. See @Ben Ling’s answer. Outgoing changes: git log @{u}.. Incoming changes: git log [email protected]{u}

    – Debajit

    Jun 12, 2013 at 22:59


  • 17

    @Nocturne I just want to point out that when this answer was posted, the @{u} syntax wasn’t available yet, it only became available on February 12, 2010. Also, @{u} won’t work if the local branch isn’t configured with an upstream. Finally, @{u} doesn’t currently have tab completion support, <remote>/<branch> with tab completion remains one of the fastest ways to get this information, and it will work whether an upstream is configured or not.

    – user456814

    Jul 1, 2014 at 0:46


813

To see all commits on all branches that have not yet been pushed:

git log --branches --not --remotes

To see the most recent commit on each branch, as well as the branch names:

git log --branches --not --remotes --simplify-by-decoration --decorate --oneline

9

  • 10

    This is awesome. In a related scenario I had two local branches with two upstream branches, and one local hand been merged into the other. I wanted to know which commits were safe to rebase, but the normal git log master..HEAD wouldn’t work since there were multiple upstreams. This post led me to git log MyBranch --not --remotes to show all the commits that have not been pushed to any upstream in a single branch.

    – pavon

    Jul 12, 2014 at 2:10

  • I understand that your second command is also listing the commits that aren’t pushed yet, only it shows just one per branch.

    – Stephane

    Mar 30, 2016 at 6:19

  • --decorate shows the branches as well. --graph makes it even more obvious.

    – Ray

    Dec 20, 2016 at 11:19

  • Note that these commands list only commits that haven’t been pushed in any branch. Example: say you have branch develop with branch feat-NewThing. You make changes locally to feat-NewThing. (Log has changes.) You then push feat-newThing to it’s remote branch. (Log is empty). You merge local feat-newThing to develop locally. Assuming a fast-forward, the log still has no changes.

    – Patrick W

    Jan 17, 2017 at 0:02

  • 2

    This is the actual solution. The only one that works generally without the need to specify a branch or the need to have an upstream defined.

    Sep 5, 2017 at 10:02

365

Show all commits that you have locally but not upstream with:

git log @{u}..

@{u} or @{upstream} means the upstream branch of the current branch (see git rev-parse --help or git help revisions for details).

4

  • 20

    On Windows, I needed to enclose the final argument in quotes, like: git log “@{u}..”

    Nov 15, 2016 at 13:48


  • 2

    git log @{u}.. -p One of the most useful options is -p, which shows the differences introduced in each confirmation.

    – mQuiroz

    Sep 20, 2018 at 18:50

  • 3

    Possibly better git log @{push}.. , see another answer.

    Nov 26, 2019 at 12:13

  • I found this one is the best answer. I also found that there is no way on Earth I’ll remember it without a cheat sheet. Why didn’t the git devs chose something obvious, and in line with git status, since we want to know the status of a situation. git status -v would have made so much more sense.

    May 12, 2021 at 15:49