Getting git Working on Android Devices

I have this small project for my brother that I need to create backend functions for his website. But I haven't been able to work on it as much (or fast) as I'd like to since I'm always doing things away from my computer. I could bring around my notebook with me but it's not that convenient. Then I thought it would be nice if I could use my old-yet-still-functioning-good cellphone, thunderbolt, for coding and could share it with my other computers since I carry it with me all the time.

Bang! Why not! Then I started searching apps for editors, web servers, and version control, etc... Editor and web server were relatively easy to find. I decided to use Vim Touch for editor and AndroPHP for web server. A problem was with a version control app. I've used git for other projects so I wanted to use it for this but I couldn't find a suitable app. When I was almost giving up this whole idea, I realized that I had Terminal IDE and gave a try to see if it had git installed. VoilĂ ! It had git installed.

Disclaimer:
The information below is the result of my researches in the Internet and of my experiences. It is solely used for my purpose and may not be suitable for others.

Getting its environment for git and remote origin:

The version of git on my cellphone is 1.7.8: $ git --version git version 1.7.8.163.g9859a.dirty

I have a remote repository at bitbucket.org and tied to clone it to my cellphone: $ git clone https://[username]@bitbucket.org/[username]/[reponame].git Cloning into '[reponame]'... fatal: cannot exec 'git-remote-https': Permission denied

Oops... it's not working. After googling, I found that Terminal IDE doesn't support HTTPS for authentication. That leaves me with SSH authentication.


Generating SSH Keys:
Terminal IDE comes with the command dropbearkey which is a relatively small SSH server and client that's capable of running on a variety of POSIX-based platforms. It's easy to create a new key: $ mkdir ~/.ssh $ dropbearkey -t rsa -f ~/.ssh/id_rsa This will create a passphrase-less pair of public/private keys. If the public key needs to be viewed later time, this command does the job: $ dropbearkey -y -f ~/.ssh/id_rsa


Configuring SSH:
SSH now needs to be mapped to a new key: $ vim ~/.bashrc --------------------------------- alias ssh='ssh -i ~/.ssh/id_rsa'

But git uses a bit different way to handle this: $ vim /data/data/com.spartacusrex.spartacuside/files/bin/ssh_git --------------------------------- #!/data/data/com.spartacusrex.spartacuside/files/system/bin/bash exec ssh -i ~/.ssh/id_rsa "$@"

Then make it executable: $ chmod 755 /data/data/com.spartacusrex.spartacuside/files/bin/ssh_git

And set an environment variable: $ vim ~/.bashrc --------------------------------- export GIT_SSH=~/bin/ssh_git

[Edit: I forgot to mention about registering the public key to Bitbucket]

Note: If you get No auth methods could be used error, most likely ssh is not loading your key or you forget to register the public key to your server (in my case bitbucket.org) $ ssh -T git@bitbucket.org ssh: connection to git@bitbucket.org:22 No auth methods could be used.

Before connecting to bitbucket.org, the public key must be registered to my account at bitbucket. To do so, convert the key to OpenSSH format: $ dropbearkey -y -f ~/.ssh/id_rsa | grep "^ssh-rsa" > ssh_key

Then, log into bitbucket.org. Go to AvatarManage accountSSH KeysAdd Key. Then copy the content of ssh_key file generated above. Once this is done, the connection should be successfully made.

Now restart Terminal IDE and try to connect to bitbucket.org:

$ ssh -T git@bigbucket.org logged in as [username]. You can use git or hg to connect to Bitbucket. Shell access is disabled.

Good. That means it's successfully connected to the server.


Cloning my repository:
First create a directory where I can clone my repository into: $ ln -s /mnt/sdcard/www www && cd www

Then clone it from my account at bitbucket.org: $ git clone git@gitbucket.org:[username]/[repository_name].git


Setting up the environment for git:
Let's configure git: $ git config user.name "[username]" $ git config user.email "[username]@[server]"

Git is a very versatile tool and it has some very versatile ways to be configured: $ vim ~/.bashrc --------------------------------- export GIT_AUTHOR_NAME="[username]" export GIT_AUTHOR_EMAIL="[username]@[server]" export GIT_COMMITTER_NAME=$GIT_AUTHOR_NAME export GIT_COMMITTER_EMAIL=$GIT_AUTHOR_EMAIL

With all of this, my old-but-trusting thunderbolt becomes my primary coding device!

That's all!
-gibb

4 comments

  1. Mindaugas

    Thanks for this tutorial. It works well on my nexus 7, even phone note3. I set ssh to bitbucket. Now I want to find script to ssh 2 more servers, github and my hostgator.
    Do you know how it can be done, or any tutorials how to do it. Thanks

Post a comment

You may use the following HTML:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>