Alias for unpushed commits, no matter what branch I'm on?

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.

  • How to manage multiple similar but different projects with git?
  • Git & external backup. Subdirectory is empty, I'd rather it not be.
  • git: grep file in all previous versions
  • How to squash all git commits into one?
  • Removing massive overhead from Git repository
  • Setting upstream branch to remote with different name than your local
  • What would the correct command be to show unpushed changes whether or not I’m on a branch?

  • Gitlab: Unable to clone by http (cloning by ssh works well)
  • Multiple streams over single project in Git?
  • How to shallow clone a specific commit with depth 1?
  • Pull a commit from a Gerrit repository using its commit ID only
  • Removing subproject commit from github
  • Xcode: Source control is disabled
  • 3 Solutions collect form web for “Alias for unpushed commits, no matter what branch I'm on?”

    If you just want to see the outgoing commits for the current branch, you can use the following:

    git config alias.unpushed "log @{u}.. --pretty=format:'%h %an %s'"
    

    This causes git log to show all commits reachable from HEAD excluding 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/foo if the checked out branch is foo).

    If you want to see all unpushed commits from all branches, do this:

    git config alias.unpushed "log --all --not --remotes --tags --pretty=format:'%h %an %s'"
    

    The above causes git log to 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 --tags argument sometimes).

    I personally use the following aliases to show unpushed commits:

    # unpushed:  graph of everything excluding pushed/tag commits
    # with boundary commits (see below for 'git g' alias)
    git config alias.unpushed '!git g --not --remotes --tags'
    
    # go:  _G_raph of _O_utgoing commits with boundary commits
    # (see below for 'git gb' alias)
    git config alias.go '!git gb @{u}..'
    
    # g:  _G_raph of everything with boundary commits
    git config alias.g '!git gb --all'
    
    # gb:  _G_raph of current _B_ranch (or arguments) with boundary commits
    git config alias.gb '!git gbnb --boundary'
    
    # gbnb:  _G_raph of current _B_ranch (or arguments) with _N_o _B_oundary commits
    git config alias.gbnb 'log --graph --date-order --pretty=tformat:"%C(yellow)%h%Creset %C(magenta)%aE %ai%Creset %C(green bold)%d%Creset%n        %s"'
    

    For simple repositories I use the git g alias as my primary method of exploring the commits. For complex repositories (dozens of branches), I generally use git gb to show specific branches or ranges of commits. When I want to see how git push will change the remote reference (my push.default is set to upstream), I use git 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 use git unpushed.

    I use git-wtf for this and other questions.

    This will do it:

    git config alias.unpushed "log $(git rev-parse --symbolic-full-name @{u})..HEAD --pretty=format:'%h %an %s'"
    

    It compares the full name of the upstream tracking branch (e.g. refs/remotes/origin/master) with HEAD. The full name is a valid refspec for your average git operation.

    If you use fetch instead of pull, and want commits in either branch but not both, use ... syntax instead of .. syntax in the command.

    Git Baby is a git and github fan, let's start git clone.