git outgoing

2012-11-20 12:05

Now that I don’t use Mercurial at work anymore, I’ve found that despite its shortcomings (hg status taking 10+ seconds?!) it has some few nice features. One of those is hg outgoing, which shows you which changesets you are going to send to remote repo in your next push. A quick glance at this list will typically ensure that everything is in order, or allow to amend some commits before making them public.

In Git you can do the similar by applying a filter to git log:

  1. $ git log origin/master..

But while origin is most often the remote you want to compare against, the master branch is typically not the one where most of development takes place. So if we want to create a git outgoing command, we would rather check what the current branch is and compare it with its remotely tracked equivalent:

  1. #!/bin/sh
  2. BRANCH=$(git name-rev HEAD 2>/dev/null | awk "{ print \$2 }")
  3. git log origin/$BRANCH..

Simply naming this script git-outgoing and making it executable somewhere within your $PATH (e.g. /usr/bin) will make the git outgoing command available:

  1. $ git outgoing
  2. commit 8c96c21c420dd10a34441cbd7d4c6904a6077716
  3. Author: Karol Kuczmarski <karol.kuczmarski@gmail.com>
  4. Date:   Tue Nov 20 11:51:44 2012 +0100
  5.  
  6.     Add .gitignore
  7.  
  8. commit 8a51a4f39b383c9dff64532403ab3922bc2ae13c
  9. Author: Karol Kuczmarski <karol.kuczmarski@gmail.com>
  10. Date:   Tue Nov 20 11:50:01 2012 +0100
  11.  
  12.     Comments in install script

There are few untold assumptions here, like the fact that branch names must match on both local and remote repo. If you find yourself breaking those, then you’re probably better to just use git log directly.

Be Sociable, Share!
Be Sociable, Share!
Tags: , ,
Author: Xion, posted under Programming »


3 comments for post “git outgoing”.
  1. Liosan:
    November 20th, 2012 o 12:46

    I think the assumption about branch names isn’t required is you use

    1. git log origin/master..HEAD

    ?

  2. Liosan:
    November 20th, 2012 o 12:48

    … nevermind, you still need to determine the remote branch name :)

  3. Xion:
    November 20th, 2012 o 20:15

    Yeah, that’s the assumption: the script uses local branch name to determine remote branch name.

    Now, you could improve it by getting the info on what local branch pushes to what remote branch. I don’t how to do that, short of parsing the output of git remote show origin which is pretty much in natural language… So I’ll leave it as exercise for the reader ;-)

Comments are disabled.
 


© 2023 Karol Kuczmarski "Xion". Layout by Urszulka. Powered by WordPress with QuickLaTeX.com.