Android and Git: a (version controlled) love story

Back in August last year, having a big phone (or phablet as those are called nowadays) was unusual, having a Bluetooth keyboard connected to such a device was seen as weird but wanting to use that combination for writing code and store it in a VCS was considered as borderline.

In those days getting Git up and running on Android wasn’t for the faint of heart as there was no app that dared going any further than supporting read-only operations (i.e. clone and pull) and there was virtually no tutorial, guide or how-to to help in such a quest; that’s when I decided to write what ended up being the most popular piece of text I’ve ever published on the web, i.e. a full length, step by step tutorial on how to get the Git CLI experience working on Android in a Bash shell with the title of “Damngit! Git on Android FTW or how to painfully set up Git on your phone” (which now is nothing more than a redirect to this page).

Due to its popularity and to the set of instructions being a tad out of date, I’ve decided to dust that post and refresh on the topic especially since the apps landscape has changed a bit since then (and there are many more phablet/tablet-equipped developers willing to hack on the go than there used to be back in 2012).

Git apps: what’s available in the store(s)?

So let’s start with a state of the union on what is available today on the Google Play Store in term of both dedicated and git-enabled apps since the There’s an app for that meme is more valid today than ever, there’s a chance you’ll find what you need before investing more time.

The following is a list of apps I played with so far, grouped by category.

GUI clients

My pick in this category is SGit.

Git-enabled IDEs and Editors

I’m a happy DroidEdit user which is also what I use as a note-taking “cloud” app on my phone after I abandoned Evernote and SimpleNote in favor of a private git repository hosted at BitBucket filled with an organized collection of markdown text files, but that’s material for another post.

CLI environments

I have to admit ZShaolin is a very attractive package and while Terminal IDE needs a bit of tweaking to get Git to work correctly with remotes, my preference goes to the latter as easy access to tools that have been in the public domain for over 30 years should be free on any platform and also because I have a mild preference for Bash over ZSH.

So, if you haven’t found and IDE, Editor or GUI client that satisfies your VCS needs while going through the lists above and for whatever reason ZShaolin is not your cup of tea then fear not and hold tight as we’ll go through the steps to set up Terminal IDE’s Git tool-chain to work as expected.

Setting up Terminal IDE for Git work-flows

Follow this steps to get through a spiral of painful joy and be able to successfully run git push against your remotes and call yourself a victor:

  1. The obvious, we need to get Terminal IDE installed on our devices
  2. Since there’s only support for SSH, we’ll also need a pair of private/public RSA keys
    • You can generate those on any machine that can run ssh-keygen and then move it to /data/data/com.spartacusrex.spartacuside/files/.ssh (which could be a bit tricky depending on your understanding of Android’s sandboxed file system for apps’ data)
    • You can generate the keys using dropbearkey directly in Terminal IDE’s prompt: bash mkdir ~/.ssh dropbearkey -t rsa -f ~/.ssh/id_rsa This will create a passphrase-less pair of keys fitting our Git needs and print out the public token (you can retrieve it at any time by running dropbearkey -y -f ~/.ssh/id_rsa)
  3. We’ll have to deploy the public key on the remote(s), this varies depending on your remote, e.g. on GitHub this can be done through the user settings page
  4. Now that we have keys we need to tell SSH and Git to use the correct identity, you can use either vim or nano as the shell supports both

    1. Create a script for Git to use the identity, e.g. nano ~/local/bin/ssh-git bash #!/data/data/com.spartacusrex.spartacuside/files/system/bin/bash exec ssh -i ~/.ssh/id_rsa "$@"
    2. Make the script executable by running chmod +x ~/local/bin/ssh-git
    3. Edit the .bashrc settings file that comes with Terminal IDE, e.g. nano ~/.bashrc: bash export GIT_SSH=~/local/bin/ssh-git
    4. Shutdown and re-start Terminal IDE
  5. Now we need to associate a Git user to the identity, unfortunately the version of git bundled with Terminal IDE has issues with reading user name and email from config files set via the git config command so we’ll have to resort to a different method

    1. Edit .bashrc once again and add the following bash export GIT_AUTHOR_NAME="USER NAME" export GIT_AUTHOR_EMAIL="user@email.address" export GIT_COMMITTER_NAME=$GIT_AUTHOR_NAME export GIT_COMMITTER_EMAIL=$GIT_AUTHOR_EMAIL If your remote is GitHub make sure the user name and email match the ones used for your GitHub user
    2. Shutdown and re-start Terminal IDE

If you got so far to read this line, then congratz! You can start using your pocket-able Git setup!

To save any remain of sanity I’d suggest you get an USB OTG or Bluetooth keyboard, the soft keyboard that comes with Terminal IDE is ok but nothing can replace a physical keyboard when coding/hacking.

Happy Git-ing!