Git aliases: incoming a la Mercurial

I have been using Mercurial in a professional setting for more than a year now. I still use git for personal projects, and what I miss the most from Mercurial are the incoming and outgoing commands.

These commands allow you to see at a glance which changesets you will pull / push. Here’s how to replicate this behaviour using git:

git config --global alias.out '! git fetch; BRANCH="$(git branch | grep \* | cut -d " " -f2;)"; git log ^origin/$BRANCH $BRANCH;'
git config --global alias.in '! git fetch; BRANCH="$(git branch | grep \* | cut -d " " -f2;)"; git log origin/$BRANCH ^$BRANCH;'

Here it is in action:

pmourlanne@pmourlannelaptop:~/repos/monrepo$ git out
commit 476a4db2f53408b3cdf520682f4949471b94ff71
Author: Pierre Mourlanne <pmourlanne@mail.com>
Date: Fri Jun 9 14:47:27 2017 +0200

Example commit to show git out :>

Since the last call is a simple git log, you can customize it as you wish, using your preferred format for example.

Advertisements

Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: