19

How can I get a list of all push commands to or from a particular remote in git?

For my case, this would be OK to run on either the remote or the local repos.

For bonus points, how would I get a list of all successful push commands?

Clayton
  • 1,967
  • 4
  • 18
  • 26

2 Answers2

24

This method will only give you the successful pushes, but it may still be useful to you:

When you push to a branch in a remote that corresponds to one of your remote-tracking branches, and that push is successful, the remote-tracking branch will be updated. In the default case where you've cloned from a repository this typically means that successful pushes to master in the remote origin will update the remote-tracking branch origin/master. Changes to origin/master are recorded in the reflog, so you can find the successful pushes with:

 git reflog show origin/master

For example, in one of my repositories, you'll see:

17f2303 refs/remotes/origin/master@{0}: fetch origin: fast-forward
dd7e0ac refs/remotes/origin/master@{1}: fetch origin: fast-forward
1788ffe refs/remotes/origin/master@{2}: fetch origin: fast-forward
9763bbc refs/remotes/origin/master@{3}: fetch origin: fast-forward
058d0d6 refs/remotes/origin/master@{4}: fetch origin: fast-forward
921f0f1 refs/remotes/origin/master@{5}: fetch origin: fast-forward
8483afd refs/remotes/origin/master@{6}: update by push
18d527f refs/remotes/origin/master@{7}: update by push
1a0fc4a refs/remotes/origin/master@{8}: fetch origin: fast-forward
b19afc6 refs/remotes/origin/master@{9}: fetch origin: fast-forward
9253285 refs/remotes/origin/master@{10}: fetch origin: fast-forward
dfa664f refs/remotes/origin/master@{11}: fetch origin: fast-forward
30ee7c0 refs/remotes/origin/master@{12}: update by push
ad11e76 refs/remotes/origin/master@{13}: fetch origin: fast-forward
c337975 refs/remotes/origin/master@{14}: update by push
1ff03bd refs/remotes/origin/master@{15}: update by push
7fb1c8d refs/remotes/origin/master@{16}: fetch origin: fast-forward
452c8fa refs/remotes/origin/master@{17}: fetch origin: fast-forward
6c79a16 refs/remotes/origin/master@{18}: update by push
11d9c4a refs/remotes/origin/master@{19}: fetch origin: fast-forward

For example, you can tell from this that my most recent push updated origin/master from 18d527f to 8483afd.

If you need to rely on this, you'll need to stop the reflog from expiring after the default time (90 days IIRC).

Mark Longair
  • 446,582
  • 72
  • 411
  • 327
  • Perfect! Thank you. FWIW, my reflog is showing entries from the last 9 months, and I haven't done anything to affect its behavior since I first installed. – Clayton Jan 09 '12 at 16:22
  • 2
    @Clayton: That probably just means you haven't had `gc --auto` trigger yet; it'll expire reflogs older than that default 90 days. Just set `gc.reflogExpire` to `never` (or something larger) if you want things to stay that way. – Cascabel Jan 09 '12 at 18:05
  • For git learners: to set the reflog to never expire for all your local repos do: `git config --global gc.reflogExpire never` at the command line. – Craig S. Anderson Apr 15 '15 at 22:38
4

Tortoise-Git for Windows has "Show RefLog" option https://tortoisegit.org/docs/tortoisegit/tgit-dug-update.html, which includes date of commit.

Michael Freidgeim
  • 26,542
  • 16
  • 152
  • 170