How to install Git on Android

If you need to work with Git while on the go, install it on Android with the help of Termux.

git-logo.jpg

There may be times when you need to work with Git, and the only device you have is your Android smartphone. When that’s the case, what do you do? Thanks to a handy tool called Termux, it is possible to install the command line Git tool on a mobile device. 

I’m going to walk you through the process of getting this up and running. I’ll demonstrate on Android 9, running on an Essential PH-1.

Once installed, you’ll have the full complement of tools found in the command line version of Git.

SEE: VPN usage policy (TechRepublic Premium)

What you need

The only things you need are a device running version 5.0 or newer of the Android platform and a GitHub account. That’s it. 

Let’s make this happen.

Installing Termux

The first thing to do is install Termux. This is done from the Google Play Store, by following these steps:

  1. Open the Google Play Store on your Android device.
  2. Search for Termux.
  3. Locate and tap the entry by Fredrik Fornwall.
  4. Tap Install.
  5. Allow the installation to complete.

Once installed, you’ll find a launcher for Termux on your home screen and/or your App Drawer. Locate that launcher and open the app. When the app opens, you should see a somewhat familiar terminal window (Figure A)

termuxa.jpg

Figure A: A terminal that should be familiar to anyone who has ever used Linux.

Installing Git and SSH

Before you can run the installation command, you need to update and upgrade. To do that, issue the command (Figure B):

apt update && apt upgrade
termuxb.jpg

Figure B: Updating and upgrading termux.

When the upgrade completes, you are ready to install both Git and SSH. To do that, issue the command:

apt install git openssh

This command (Figure C) will install both necessary apps.

termuxc.jpg

Figure C: Installing Git and OpenSSH.

Set up Git storage

It’s now time to set up Termux Storage. This is done with the command (from the Termux terminal):

termux-setup-storage

Upon running that command, you will be prompted to allow the app access to storage. Do so, and you’re ready for Git.

Connecting to GitHub

This is where it gets slightly tricky. From the Termux terminal, you must first create an ssh keypair. To do this, issue the command:

ssh-keygen -t rsa -C "EMAIL"

Where EMAIL is your email address associated with your GitHub account.

Once you generate the key, I suggest you use the scp command to copy it to a desktop computer. So change into the .ssh directory (on Termux) with the command:

cd .ssh

From within that directory, issue the command:

scp id_rsa.pub USER@IP:/home/USER/

Where USER is a remote username and IP is the remote address of a desktop on the same network as your Android device (that accepts SSH connections). 

Once you have that file stored on a remote desktop, you need to log into GitHub (from the desktop now housing the .pub file) and go to Settings | SSH Keys. Copy that id_rsa.pub key into Git and save it. 

Logging into Git

Now that you copied your SSH public key to GitHub, you can log into your GitHub account with the command:

ssh -T git@github.com

Once you authenticated, you are ready to start working with Git from your Android device. Create repositories, push, pull, and more. You might want to also do yourself a favor and install the nano editor, via Termux (with the command apt install nano), so you can actually edit code.

And there you go. A handy way to work with Git on your Android device. Now … git to work.

Also see

Source link

Advertisements

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.