Zachary Flower

Experimenting with life. One line at a time.

My Two Favorite Git Aliases
Screenshot_5_9_13_5_04_PM-2

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.

  • Pingback: My Two Favorite Git Aliases : alexking.org

  • http://jondavidjohn.com jondavidjohn

    Very nice. One edit I would make is to grab the current branch’s upstream branch (tracking branch) instead of hard coding master.

    Instead of

    …%s %C(white)- %ar%Creset’ ..origin/master)

    You can do

    …%s %C(white)- %ar%Creset’ ..$(git rev-parse –abbrev-ref –symbolic-full-name @{u}))

    This will make sure you’re checking against the branch you’re likely to push to and pull from at all times, not just when on master.

    • http://www.zacharyflower.com Zachary Flower

      Great suggestion! I’ve updated the aliases accordingly.

      • http://jondavidjohn.com jondavidjohn

        And now looking at it again, since we’re already in a git command we can use

        1
        @{u}

        (referring to the current upstream branch) directly without having to run it through

        1
        git rev-parse

        So this is actually sufficient

        …%s %C(white)- %ar%Creset’ ..@{u})

        and

        …%s %C(white)- %ar%Creset’ @{u}..)