Unlike most people (I imagine) I rarely, if ever, run git pull
when refreshing my local Git repositories.
Instead, over the years I have grown accustomed to running git fetch
and git merge
separately (a pull
does both of these in one command).
The reason for this is so that I can review the log and any changes before merging the remote code into my local repo.
I would try to remember to run git log
after fetching the remote code, which by default would show the entire log history of the repo. Then I read about the dotted range notation and @
construct for specifying revisions in Git.
Using @
on is own is equal to HEAD
. Combine it in git log
with {upstream}
or {u}
to only show commit logs for the upstream branch
git log @{u}
The two-dot notation is shorthand for all commits in a range. Therefore to show only the commits from the remote upstream that have yet to be merged in my local branch I would incant
git log HEAD..@{u}
This can be made even easier by omitting HEAD
, as leaving one end of the range blank defaults to HEAD
git log ..@{u}
With this newfound knowledge I updated my gf
alias to run both commands, automatically showing me the commits I have fetched and need to review
alias gf="git fetch && git log ..@{u}"