Finding un-pushed commits on current branch through a function

Viewed 27

I've seen a lot of great posts regarding displaying "unpushed" file commits. I've sort of constructed a function to perform - getting the list of unpushed commits on the current branch.

What I have in my .gitconfig is:

notpushed = "!f() { git rev-parse --abbrev-ref HEAD | git diff --stat --cached origin/$1; }; f"

Apparently, it's the $1 that is wrong. I am simply trying to do an "automatic" selection of the current branch.

Any ideas would be great.

1 Answers

Piping is not the right tool in this situation. Try :

notpushed = "!f() { branch=$(git rev-parse --abbrev-ref HEAD); git diff --stat --cached origin/$branch; }; f"

There is actually a shortcut to "the upstream of the current branch" : @{u}

You can change your alias to :

notpushed = diff --stat --cached @{u}
Related