Tagged: git

Termux is the ONE for Android!

Ever since I learned Terminal IDE was not supported for Android 5.0 Lollipop, I was heartbroken because there weren't any git client programs as good as git on Terminal IDE. I was using SGit but wasn't really happy because of lack of flexibility, features, and ease of use.

However, I finally found the one that works today! It's called Termux. Termux is a terminal emulator, just like Terminal IDE, but it comes with an extensive Linux package collections you can install and manage packages you want. Of course, it has git in its collection. So, I can say "bye, bye" to SGit now.

IMHO, Termux is for Android 5.0 Lollipop and above, and Terminal IDE is for Android 4.4 Kitkat and below.

Disclaimer:
The information in this site 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. I will NOT take any responsibility of end result after following these steps (although I will try to help if you send me your questions/problems).

Ok, the installation and configuration of Termux and git were easier than those of Terminal IDE in my opinion. Termux comes with a minimum base system. At this point, it doesn't do much so you'd need to install some packages. After getting Termux installed on my Galaxy Note 4, I opened it and typed below to update packages: $ apt update

With a bunch of messages, packages are updated. Then ran the following command to install git: $ apt install git

No problem here. I then installed ssh. As you may know, bitbucket.org offers two ways to access a git repository, https and ssh. I could go either way, but ssh is such a useful utility. So, I installed it at this time: $ apt install openssh

Now, the fun part starts - configuration. I've set up my web server Bit Web Server to look into /sdcard/www/ for source codes, so I tried to clone codes from my git repo, but it failed with "Permission Denied" error. Hmm... is this because Termux doesn't have write permissions for security? Well, no problem. I can seem to clone into /data/data/com.termux/home/ and copy the source codes into /sdcard/www/: $ git clone https://[user_name]@bitbucket.org/[repo_name]/[repo_name].git $ cp -r [repo_name] /sdcard/www/

After copying into the www directory, I learned that I can still run git commands like git push, git pull, etc... without any errors. Fantastic!! This means I don't need to copy back and forth between /data/data/com.termux/home/ and /sdcard/www/ every time I make updates.

Now, it's time to finish up by configuring git and Termux's user home environments.

For git, ran the following commands to set up user information: $ git config user.name "[username]" $ git config user.email "[username]@[server]"

Then edited the .bashrc file for some aliases. I created ~/.bashrc with some start up configurations for the shell, but it didn't seem to be taking it after restarting Termux. After poking around, I found a bashrc file that seems to be globally used for Termux in /data/data/com.termux/files/usr/etc/: $ cd /data/data/com.termux/files/usr/etc/ $ vim bash.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 PS1='\[\e[00;32m\]\A \[\e[00;91m\]\u\[\e[01;93m\]@\h\[\e[00;37m\][\[\e[01;34m\]\w\[\e[00;37m\]]\n\[\e[47m\]\[\e[1;30m\]$\[\e[00m\] ' set -o vi

With all of these, git is ready for Android 5.0 Lollipop!

That's all!
-gibb

Getting git working on Galaxy Note 4

Yes! I finally received Samsung Galaxy Note 4 - Frost White on 11/3/2014, a little more than week later than proposed shipping date from Verizon. Galaxy Note 4 is an amazing, amazing device. It's super fast and its display is just gorgeous. There are so much to say about this phone but for full reviews and specs, you can always "Google It".

At any rate, after a few days of playing with it, naturally, I decided to make it my web development device in place of old Thunderbolt. So, I started following my own blog, Getting git Working on Android Device. But when I tried to make a test connection to bitbucket.org, I got following error: $ ssh -T git@bitbucket.org ssh: connection to git@bitbucket.org:22 No auth methods could be used.

Hmm... what's going on? I started digging and found that I forgot to mention registering the public key to bitbucket.org. Oops. After a year of its original post, I found a missing step in my post. How embarrassing! I made a correction so hopefully all make sense now.

Since I have all the steps and explanation in Getting git Working on Android Device, I won't go into details of each step again, but instead, I'll list the summary of commands used to make it happen: //OPEN Terminal IDE $ git --version git version 1.7.8.163.g9859a.dirty $ mkdir ~/.ssh $ dropbearkey -t rsa -f ~/.ssh/id_rsa $ dropbearkey -y -f ~/.ssh/id_rsa $ vim ~/.bashrc --------------------------------- alias ssh='ssh -i ~/.ssh/id_rsa' $ 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 "$@" $ chmod 755 /data/data/com.spartacusrex.spartacuside/files/bin/ssh_git $ vim ~/.bashrc --------------------------------- export GIT_SSH=~/bin/ssh_git $ dropbearkey -y -f ~/.ssh/id_rsa | grep "^ssh-rsa" > ssh_key //COPY THE PUBLIC KEY TO bitbucket.org and Restart Terminal IDE $ ssh -T git@bigbucket.org logged in as [username]. You can use git or hg to connect to Bitbucket. Shell access is disabled. $ ln -s /mnt/sdcard/www www && cd www $ git clone git@bitbucket.org:[username]/[repository_name].git $ 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

That's all!
-gibb

Disclaimer:
The information in this site 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. I will NOT take any responsibilities of end result after following these steps (although I will try to help if you send me your questions/problems).

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

Git Basics

I sometimes develop websites for personal interests or for friends. Since I'm the only one to work on them, I did not really pay too much attention on version control. But there was a small project that I worked for my friend, which required me to look into a version control system (because he who has no coding experience also wanted to help updating source codes).

I once tried to learn subversion but couldn't really get the hang of concepts of trunks, branching, etc... So, I didn't want to try subversion. Then I met git.

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.

Git First-time System Setup:

After installing, execute below commands to set up the system. This is done only one time: $ git config --global user.name "user-name" $ git config --global user.email user@email.com $ git config --global core.editor "gvim -f"

First-time Repository Setup

These steps are necessary each time a new repository is created. First, navigate to the root directory of the website/applicew repository: $ git init Initialized empty Git repository in /home/<username>/www/<project_name>/.git/

By default, Git tracks the changes of all the files, but we can use .gitignore that locates in the application root directory to control what to track. $ vim .gitignore ----------------------------------------- # Ignore bundler config /.bundle # Ignore the default SQLite database. /db/*.sqlite3 # Ignore all logfiles and tempfiles. /log/*.log /tmp # Ignore other unneeded files. doc/ *.swp * ̃ .project

More to come...!
-gibb