Some useful git commands

gitHub is an amazing piece of functionality. The user interface is so amazing that BitBucket simply ripped it off. Yes, without any regrets. I mean people are bound to notice that sort of stuff but still these things happen. Anyways, I came across some really handy git commands and would like to share them and just make a record of it in case I need to refer to them.

  1. git daemon
  2. I found out about git-daemon through a blog post by the gitHub guys. Apparently, they have rewritten the daemon in Erlang. So, as per the documentation git-daemon basically starts up a server in your repository and then you can use it for doing commands like git-clone and git-fetch. It gives a read-only access as default.

    Now, you would say why the hell do I need to run my own service to serve the code. Why do you think I am paying gitHub for? Good question but let us imagine a scenario. You are about to push to staging (I dare not say live because you don’t push your “dodgy” untested code to live servers) for quality assessment team and gitHub goes down (it has an amazing uptime but you never know) and you need to pass your code to the “Lead developer” sitting in a different physical location. git-daemon to the rescue. The only issue would be to fix firewall to allow connections on 9418(default port).

    How do I do it?

    1) touch decoct/git-daemon-export-ok
    2) git-deamon --base-path=. --verbose
    

    The first line creates a file in the repository that you want to serve and its presence tells git-daemon that it is ok to serve files in these repository. git-daemon would refuse any requests in its absence.

    The second line sets the base-path to the current directory and now I can basically serve any git-repository in the current directory that has git-daemon-export-ok file in it.

  3. git instaweb
  4. As the name suggests, creates a web interface so that one can browse the local repository. Just do:

    git instaweb --httpd=webrick
    

    Once you run the command it will open up the broser window and you can basically look at all the information about your repository. Simply amazing.

  5. git shortlog
  6. So, I want to look at a consolidated report of the number of commits by my team. git shortlog to the rescue and here’s what you need to do:

    git shortlog -n  -s -b master
    

    Run this command inside your repository and you would be amazed by what you see. I know you can probably do all this stuff in svn but I am just excited to find the functionality in git.

    This is just a teaser. You should go and explore the commands further. I know I would because I am going to write the git-daemon in Scala. And there is a nice article on all this by gitHub guys.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>