# git diff – Viewing unpushed Git commits

## The Question :

1866 people think this question is useful

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?

The Question Comments :
• 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
• @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.
• 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
• This particular StackOverflow question has the highest number of correct answers that all work yet don’t make any sense.
• @josh-buhler Sorry, I down-voted accidentally… while I attempted to click the ‘STAR’. Re-attempted to up-vote, but, didn’t work!

## The Answer 1

1938 people think this answer is useful
git log origin/master..HEAD



You can also view the diff using the same syntax

git diff origin/master..HEAD



## The Answer 2

735 people think this answer is useful

If you want to see all commits on all branches that aren’t pushed yet, you might be looking for something like this:

git log --branches --not --remotes



And if you only want to see the most recent commit on each branch, and the branch names, this:

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



## The Answer 3

336 people think this answer is useful

You can 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).

## The Answer 4

197 people think this answer is useful

This worked for me:

git cherry -v



## The Answer 5

68 people think this answer is useful

You can do this with git log:

git log origin..



Assuming that origin is the name of your upstream, leaving off any revision name after .. implies HEAD, which lists the new commits that haven’t been pushed.

## The Answer 6

51 people think this answer is useful

All the other answers talk about “upstream” (the branch you pull from).
But a local branch can push to a different branch than the one it pulls from.

master might not push to the remote tracking branch “origin/master“.
The upstream branch for master might be origin/master, but it could push to the remote tracking branch origin/xxx or even anotherUpstreamRepo/yyy.
Those are set by branch.*.pushremote for the current branch along with the global remote.pushDefault value.

It is that remote-tracking branch which counts when seeking unpushed commits: the one that tracks the branch at the remote where the local branch would be pushed to.
The branch at the remote can be, again, origin/xxx or even anotherUpstreamRepo/yyy.

# Git 2.5+ (Q2 2015) introduces a new shortcut for that: <branch>@{push}

See commit 29bc885, commit 3dbe9db, commit adfe5d0, commit 48c5847, commit a1ad0eb, commit e291c75, commit 979cb24, commit 1ca41a1, commit 3a429d0, commit a9f9f8c, commit 8770e6f, commit da66b27, commit f052154, commit 9e3751d, commit ee2499f [all from 21 May 2015], and commit e41bf35 [01 May 2015] by Jeff King (peff).
(Merged by Junio C Hamano — gitster in commit c4a8354, 05 Jun 2015)

## sha1_name: implement @{push} shorthand

In a triangular workflow, each branch may have two distinct points of interest: the @{upstream} that you normally pull from, and the destination that you normally push to. There isn’t a shorthand for the latter, but it’s useful to have.

For instance, you may want to know which commits you haven’t pushed yet:

git log @{push}..



Or as a more complicated example, imagine that you normally pull changes from origin/master (which you set as your @{upstream}), and push changes to your own personal fork (e.g., as myfork/topic).
You may push to your fork from multiple machines, requiring you to integrate the changes from the push destination, rather than upstream.
With this patch, you can just do:

git rebase @{push}



rather than typing out the full name.

## for-each-ref: accept “%(push)” format

Just as we have “%(upstream)” to report the “@{upstream}” for each ref, this patch adds “%(push)” to match “@{push}“.
It supports the same tracking format modifiers as upstream (because you may want to know, for example, which branches have commits to push).

If you want to see how many commit your local branches are ahead/behind compared to the branch you are pushing to:

git for-each-ref --format="%(refname:short) %(push:track)" refs/heads



## The Answer 7

42 people think this answer is useful

Handy git alias for looking for unpushed commits in current branch:

alias unpushed = !GIT_CURRENT_BRANCH=$(git name-rev --name-only HEAD) &amp;&amp; git log origin/$GIT_CURRENT_BRANCH..$GIT_CURRENT_BRANCH --oneline  What this basically does: git log origin/branch..branch  but also determines current branch name. ## The Answer 8 36 people think this answer is useful You could try…. gitk  I know it is not a pure command line option but if you have it installed and are on a GUI system it’s a great way to see exactly what you are looking for plus a whole lot more. (I’m actually kind of surprised no one mentioned it so far.) ## The Answer 9 34 people think this answer is useful I had a commit done previously, not pushed to any branch, nor remote nor local. Just the commit. Nothing from other answers worked for me, but with: git reflog  There I found my commit. ## The Answer 10 29 people think this answer is useful git branch -v will show, for each local branch, whether it’s “ahead” or not. ## The Answer 11 21 people think this answer is useful I use the following alias to get just the list of files (and the status) that have been committed but haven’t been pushed (for the current branch) git config --global alias.unpushed \ "diff origin/$(git name-rev --name-only HEAD)..HEAD --name-status"



then just do:

git unpushed



## The Answer 12

13 people think this answer is useful

I believe the most typical way of doing this is to run something like:

git cherry --abbrev=7 -v @{upstream}



However, I personally prefer running:

git log --graph --decorate --pretty=oneline --abbrev-commit --all @{upstream}^..



which shows the commits from all branches which are not merged upstream, plus the last commit in upstream (which shows up as a root node for all the other commits). I use it so often that I have created alias noup for it.

git config --global alias.noup \
'log --graph --decorate --pretty=oneline --abbrev-commit --all @{upstream}^..'



## The Answer 13

11 people think this answer is useful

I suggest you go see the script https://github.com/badele/gitcheck, i have coded this script for check in one pass all your git repositories, and it show who has not commited and who has not pushed/pulled.

Here a sample result

## The Answer 14

9 people think this answer is useful

It is not a bug. What you probably seeing is git status after a failed auto-merge where the changes from the remote are fetched but not yet merged.

To see the commits between local repo and remote do this:

git fetch



This is 100% safe and will not mock up your working copy. If there were changes git status wil show X commits ahead of origin/master.

You can now show log of commits that are in the remote but not in the local:

git log HEAD..origin



## The Answer 15

9 people think this answer is useful
git cherry -v



This will list out your local comment history (not yet pushed) with corresponding message

## The Answer 16

8 people think this answer is useful

This worked better for me:

git log --oneline @{upstream}..



or:

git log --oneline origin/(remotebranch)..



## The Answer 17

7 people think this answer is useful

There is tool named unpushed that scans all Git, Mercurial and Subversion repos in specified working directory and shows list of ucommited files and unpushed commits. Installation is simple under Linux:

$easy_install --user unpushed  or $ sudo easy_install unpushed



to install system-wide.

Usage is simple too:

$unpushed ~/workspace * /home/nailgun/workspace/unpushed uncommitted (Git) * /home/nailgun/workspace/unpushed:master unpushed (Git) * /home/nailgun/workspace/python:new-syntax unpushed (Git)  See unpushed --help or official description for more information. It also has a cronjob script unpushed-notify for on-screen notification of uncommited and unpushed changes. ## The Answer 18 5 people think this answer is useful To list all unpushed commit in all branches easily you can use this command:  git log --branches @{u}..  ## The Answer 19 4 people think this answer is useful If the number of commits that have not been pushed out is a single-digit number, which it often is, the easiest way is: $ git checkout



git responds by telling you that you are “ahead N commits” relative your origin. So now just keep that number in mind when viewing logs. If you’re “ahead by 3 commits”, the top 3 commits in the history are still private.

## The Answer 20

4 people think this answer is useful

Similar: To view unmerged branches:

git branch --all --no-merged



Those can be suspect but I recommend the answer by cxreg

## The Answer 21

3 people think this answer is useful

one way of doing things is to list commits that are available on one branch but not another.

git log ^origin/master master



## The Answer 22

1 people think this answer is useful

As said above:

But if you are using git gui

After opening gui interface, Select “Repository”->Under that “Visualize History

Note: Some people like to use CMD Prompt/Terminal while some like to use Git GUI (for simplicity)

## The Answer 23

-2 people think this answer is useful

Here’s my portable solution (shell script which works on Windows too without additional install) which shows the differences from origin for all branches: git-fetch-log

An example output:

==== branch [behind 1]

> commit 652b883 (origin/branch)
| Author: BimbaLaszlo <bimbalaszlo@gmail.com>
| Date:   2016-03-10 09:11:11 +0100
|
|     Commit on remote
|
o commit 2304667 (branch)
Author: BimbaLaszlo <bimbalaszlo@gmail.com>
Date:   2015-08-28 13:21:13 +0200

Commit on local

==== master [ahead 1]

< commit 280ccf8 (master)
| Author: BimbaLaszlo <bimbalaszlo@gmail.com>
| Date:   2016-03-25 21:42:55 +0100
|
|     Commit on local
|
o commit 2369465 (origin/master, origin/HEAD)
Author: BimbaLaszlo <bimbalaszlo@gmail.com>
Date:   2016-03-10 09:02:52 +0100

Commit on remote

==== test [ahead 1, behind 1]

< commit 83a3161 (test)
| Author: BimbaLaszlo <bimbalaszlo@gmail.com>
| Date:   2016-03-25 22:50:00 +0100
|
|     Diverged from remote
|
| > commit 4aafec7 (origin/test)
|/  Author: BimbaLaszlo <bimbalaszlo@gmail.com>
|   Date:   2016-03-14 10:34:28 +0100
|
|       Pushed remote
|
o commit 0fccef3
Author: BimbaLaszlo <bimbalaszlo@gmail.com>
Date:   2015-09-03 10:33:39 +0200

Last common commit



Parameters passed for log, e.g. --oneline or --patch can be used.

## The Answer 24

-3 people think this answer is useful
git show



will show all the diffs in your local commits.

git show --name-only



will show the local commit id and the name of commit.

## The Answer 25

-5 people think this answer is useful
git diff origin



Assuming your branch is set up to track the origin, then that should show you the differences.

git log origin



Will give you a summary of the commits.