Adding color coding for git in commandline

This command updates the global git config to show color coding for file state:
git config --global color.ui true

Comparing the branches in GIT

Use this command to list the files changed between two branches
git diff --name-status <branch-name-1>..<branch-name-2>
This gives list of all the files Modified/Added or Deleted:


M       file.txt
D       file2.txt
M       file3.txt

How to see Git branches


  • To see current branch
    • git branch
  • To see all the branches (local and remote)
    • git branch -a
  • To see only remote branches
    • git branch -r

Checking the Git config for a Repo

Assume you've sample.git checked out in a folder sample


  • CD to sample
  • Type git config -l  to see the current configuration. Example config:

user.name=ABCD
user.email=abcd@gmail.com
color.diff=auto
color.branch=auto
color.status=auto
color.showbranch=auto
alias.cpi=cherry-pick
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
remote.origin.url=https://github.com/robolectric/RobolectricSample.git
branch.master.remote=origin
branch.master.merge=refs/heads/master
branch.dev.remote=origin
branch.dev.merge=refs/heads/dev

  • Type git config -l  to edit current git configuration. 

Quick Tip on Git Tags

Creating the Tags in Git repo

  • Tagging head of the branch 

git tag -a <tag name> -m "<message to identify tag>"

  • Tagging a particular commit (last seven chars of a commit ID: ed26815)
git tag -a <tag name> -m "<message to identify tag>" ed26815

Pushing the Git Tags to repo (for sharing) 

  • By Name

git push origin <tagname>

  • Pushing all tags at once
git push origin --tags

Setting environmental variables for Android development in Mac OSX

Setting environmental variables or paths to Android SDK tools in ~/.bash_profile sounds so simple ! But its not quite standard when it comes to Mac OSX. In linux, you can simply use export command in ~/.bash_profile and your're done. But in Mac OSX, you have couple of options like bash.rc, bash_profile, /etc/profile and environment.plist etc. I was so confused when all I wanted was to simply have a environmental variable for ANDROID_HOME and want to access SDK tools like android and adb from commandline. So, all I had to do was:

  1. Open Terminal
  2. Type vi ~/.bash_profile in command line. It creates it, if its already not there
  3. Type following in vi editor:
export PATH=$PATH:/Users/PTyagi/Developer/android/sdks/android-sdk-macosx/tools:/Users/PTyagi/Developer/android/sdks/android-sdk-macosx/platform-tools

export ANDROID_HOME=/Users/PTyagi/Developer/android/sdks/android-sdk-macosx
Close the Terminal session and open new one and try echo $ANDROID_HOME to check. It should print the path to SDK home.

Forking Robolectric

I wanted to fork out Robolectric's Android sample test project as a starting point to writing my own unit tests which can run on JVM. Here are the steps I took :


Step-1: Click on "Fork" to create a fork on github for Robolectric.git 
Step-2: Clone your fork in your local machine:
git clone https://github.com/<user>/RobolectricSample.git
Step-3:  cd RobolectricSample/
Step-4: To keep track of original repository, add upstream
git remote add upstream https://github.com/pivotal/RobolectricSample.git
Note: You can bring original repository's changes in your working space by this command:
git fetch upstream
Merge changes from upstream (original repo) into your forked repo:
git merge upstream/master
Step-5: Pushing changes to forked repo:
git push origin master


Quick guide to set up Git on Mac-OSX

There is plenty of information available online about setting up Git on Mac. Here are the steps I followed to setup git on my brand new macbook.

Step 1: Install Git from here. At the time of writing, the latest Git's version is 1.8.2.
Step 2: Double click the .dmg file and follow the installer.
Step 3: Open a new terminal. Yes ! its important to open up a new one. git command may not be available in the old one.
Step 4: Configure your git !

Configuring Git

  • Configuring Username
git config --global user.name "Your Name"
  • Configuring Email
git config --global user.email "Your email"


If you're not very comfortable with command line, then you can use UI "GitHub for Mac" to do all tedious job for you. There are more Git Clients available to try!

Dealing with Java Hell using JarJar life boat

Okay, so I wanted to use Hex.encodeHexString method from org.apache.commons.codec.binary.Hex (commons-codec-1.6.jar)library to generate encoded singnature. I was able to do this in plain Java, but not in Android. I googled for a while and found out this ticket about Android not supporting the latest versions of commons-codec-1.6.jar.The solutions was to use magical "jarjar" ! But How ??? Again, I googled and come across this and this, and I came up with solution to solve mystery of using  Hex.encodeHexString method in code running on Android (Dalvik VM). Android uses old version of commons-codec jar which doesn't define org.apache.commons.codec.binary.Hex.encodeHexString method signature. Even if you add new commons-codec-1.6.jar to build path of project, code will try to refer to built-in commons-codec not the new one that you added in build path. But, if you change the package name/namespaces for commons-codec-1.6.jar, then you can easily reference from your code and finally can use Hex.encodeHexString. So, you have to create a custom jar with modified package name structure.

Here is how you can spin a new custom jar, say
commons-codec-1.6-jarjar.jar:

Step-1: Create a build.xml like follows:
<project name="generate-jarjar">
    <property name="jarjarfile" value="commons-codec-1.6-jarjar.jar"/>
    <path id="classpath">
      <pathelement location="jarjar-1.4.jar"/>
      <pathelement location="asm-2.2.3.jar"/>
    </path>
    <taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask"   classpathref="classpath"/>
    <delete file="${jarjarfile}"/>
    <jarjar destfile="${jarjarfile}">
    <zipfileset src="commons-codec-1.6.jar"/>
    <rule pattern="org.apache.**" result="org.jarjar.apache.@1"/>
    </jarjar>
</project>
Step-2: Run command "ant" from command line. This build script will generate a new jar  commons-codec-1.6-jarjar.jar, which you can add in your build path and use this new jar to import from.

You can download all the files mentioned in above script and build.xml from here.








Scheduling Repeating Local Notifications using Alarm Manager

Learn about Scheduling Repeating Local Notifications using Alarm Manager in this post .