Screenshot_5_9_13_5_04_PM-2

My Two Favorite Git Aliases

By | 4 Comments

I’m a big fan of Git. It is a super easy-to-use version control and source code management system. Before I came to Git, though, I used Mercurial, and there were three commands that I missed. Through a lot of Googling, I came across three Git aliases that have changed everything for me: incoming and outgoing.

Usage

Incoming

Command:

1
git incoming

The Incoming command will return a nicely formated list of incoming commits, the next time you do a pull.

1
2
3
$ git incoming
621d0eb - Developer Name -  (origin/master, origin/HEAD) Commit Message - 2 days ago
31d6367 - Developer Name -  Commit Message - 2 days ago

Outgoing

Command:

1
git outgoing

The Outgoing command will return a nicely formated list of outgoing commits, the next time you do a push.

1
2
3
$ git outgoing
9a0af47 - Zachary Flower -  (HEAD, master) Update Message - 5 seconds ago
b900493 - Zachary Flower -  .htaccess removed from application folder - 6 weeks ago

Setup

To add the aliases, put the following in your .gitconfig file (typically located in your home directory):

1
2
3
[alias]
    incoming = !(git fetch --quiet && git log --pretty=format:'%C(yellow)%h %C(white)- %C(red)%an %C(white)- %C(cyan)%d%Creset %s %C(white)- %ar%Creset' ..$(git rev-parse –abbrev-ref –symbolic-full-name @{u}))
    outgoing = !(git fetch --quiet && git log --pretty=format:'%C(yellow)%h %C(white)- %C(red)%an %C(white)- %C(cyan)%d%Creset %s %C(white)- %ar%Creset' $(git rev-parse –abbrev-ref –symbolic-full-name @{u})..)

Update: Changed master branch to current branch, as per jondavidjohn’s suggestion.