I’ve got a git alias that looks like this:
[alias]
unpushed = log origin..HEAD --pretty=format:'%h %an %s'
Which works great for showing “unpushed” changes when I’m on master. But, this alias doesn’t really work right when I’m on a branch.
What would the correct command be to show unpushed changes whether or not I’m on a branch?
If you just want to see the outgoing commits for the current branch, you can use the following:
This causes
git logto show all commits reachable fromHEADexcluding those reachable from the upstream branch. The@{u}..argument is equivalent to@{u}..HEAD, and@{u}is shorthand for the current branch’s upstream commit (e.g.,origin/fooif the checked out branch isfoo).If you want to see all unpushed commits from all branches, do this:
The above causes
git logto walk all references, but stop at (exclude) remote references (e.g.,origin/master) and tags. Git doesn’t distinguish between local and remote tags, so the above assumes that all tags are remote (this isn’t always true, so you may want to leave out the--tagsargument sometimes).I personally use the following aliases to show unpushed commits:
For simple repositories I use the
git galias as my primary method of exploring the commits. For complex repositories (dozens of branches), I generally usegit gbto show specific branches or ranges of commits. When I want to see howgit pushwill change the remote reference (mypush.defaultis set toupstream), I usegit go. When I want to see if there is anything anywhere in my local repository I haven’t pushed (e.g., to see if I’ll lose work if I delete the clone), I usegit unpushed.