FrankWiles.com

Git Pulled What???

I have been trying to spend a bit more time optimizing my day to day workflows. Not sure why it bugged me today, but something about my git CLI workflow didn’t feel right today.

Unlike most of my peers I bounce around between several git repos every single day rather than working in a small handful on a routine basis. When I switch I’m obviously going to git pull in the latest changes and then I often have questions.

The Questions

  1. What commits did I just pull in?

  2. What is the git diff compared to just before the pull?

I figured there had to be a way to do this without much trouble and I was pleasantly surprised to discover it is not hard to accomplish (especially when you just ask Claude hehe).

To display all of the commit messages you just pulled in you run:

bash
$ git log @{1}..

And to display the diff between before your pull and right now is:

bash
$ git diff @{1}..

The @{1} here specifically represents the “previous position of HEAD”. HEAD or @ represents the current HEAD position, @{1} the previous state, and @{2} would be two moves ago. I doubt I’ll ever use the later, but it helps to understand what the syntax is doing here.

I’ve got a pretty good memory, but I know I’m not going to remember this syntax very easily so I created two little zsh aliases to make it easier.

bash
pulllog() {
  git log @{1}..
}

pulldiff() {
  git diff @{1}..
}

Now I can very easily see what changes I just pulled in! This is a small micro-optimization of my workflow but an important one. In the past I’ve done a silly dance of:

  1. Find the last commit I wrote or remember reviewing
  2. git log <sha> or git diff <sha> from that commit

It’s multi-step for one, but it’s also prone to error on my part as it’s easy to grab the wrong commit sha or be wrong about what I felt was “last”.

Alternatives

After I made these I also discovered git aliases @{1} to ORIG_HEAD so you can also use the alternative forms of:

bash
$ git log ORIG_HEAD..
$ git diff ORIG_HEAD..

If you don’t feel like making some aliases. Another option is you can use git pull -v which will show you the commit messages but doesn’t help if you’re wanting to see the diff.

Hopefully now you will never be confused or surprised after you pull in some new code changes going forward!

Headshot of Frank Wiles

Frank Wiles

Founder of REVSYS and former President of the Django Software Foundation . Expert in building, scaling and maintaining complex web applications. Want to reach out? Contact me here or use the social links below.