369

Possible Duplicate:
Viewing Unpushed Git Commits

How do I list all commits which have not been pushed to the origin yet?

Alternatively, how to determine if a commit with particular hash have been pushed to the origin already?

CalvT
  • 3,123
  • 6
  • 37
  • 54
takeshin
  • 49,108
  • 32
  • 120
  • 164
  • 3
    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 at "Viewing Unpushed Git Commits"](http://stackoverflow.com/a/30720302/6309) – VonC Jun 08 '15 at 22:45

2 Answers2

481

git log origin/master..master

or, more generally:

git log <since>..<until>

You can use this with grep to check for a specific, known commit:

git log <since>..<until> | grep <commit-hash>

Or you can also use git-rev-list to search for a specific commit:

git rev-list origin/master | grep <commit-hash>

Dan Moulding
  • 211,373
  • 23
  • 97
  • 98
  • 3
    What if you have already `git fetch`'d, and the origin contains more commits which you haven't pulled yet? then `origin/develop` is newer than `develop` - will this answer still give the expected list of commits not yet pushed to the origin? – Adam Burley Dec 02 '15 at 16:39
  • 4
    @Kidburla Yes, this still works in that situation. `git log origin/develop..develop` will list any commits that haven't been pushed to the origin's develop branch. The reverse, `git log develop..origin/develop` will list any commits that are in origin's develop but haven't been pulled into the local develop yet. – Dan Moulding Dec 02 '15 at 18:36
  • 1
    If `` is supposed to be the current HEAD (the last commit on the checked out branch), then it can simply be omitted. The two dots are still required though: `git log origin/master..` (same as `git log origin/master..HEAD`) – CodeManX Mar 31 '16 at 17:19
  • 1
    Very well explained with the general case (second snippet). I'd expect there be a command or shortcut for that operation as it's very useful and frequently needed. Is there a way to define a shorter version of getting the commits that aren't on the remote yet but to reside on the local branch? – Konrad Viltersten Nov 29 '16 at 14:07
  • "git log origin/master..HEAD" is what worked for me. – BruceHill Mar 19 '18 at 13:45
  • Thank you for adding the `git log ..` explanation. Helped solidify my understanding. – 23r0c001 Mar 11 '22 at 23:20
41

how to determine if a commit with particular hash have been pushed to the origin already?

# list remote branches that contain $commit
git branch -r --contains $commit
Aristotle Pagaltzis
  • 112,955
  • 23
  • 98
  • 97