How to Install Git in Termux and Clone a Repository
How to Install Git in Termux and Clone a Repository
Version control is an essential part of modern software development, allowing developers to track changes, collaborate with others, and manage codebases efficiently. If you are using Termux—the powerful terminal emulator for Android—you can turn your mobile device into a portable development environment. To do this effectively, knowing how to install git termux packages and clone code repositories directly onto your device is a fundamental skill.
In this comprehensive step-by-step guide, you will learn how to set up Git inside Termux from scratch, configure your user details, clone public projects, and execute a termux git clone private repo process securely using modern authentication methods. Whether you want to test Python scripts, edit web projects, or manage dotfiles on the go, this guide covers everything you need to know.
Prerequisites for Setting Up Git in Termux
Before proceeding with the installation, ensure that your mobile development environment meets the following basic requirements:
- F-Droid Termux Installation: Make sure you are using the updated version of Termux downloaded from F-Droid or GitHub, not the obsolete version from the Google Play Store.
- Active Internet Connection: Required to download packages and pull remote repositories.
- Android Storage Permission: Granted so that Termux can interact with your device's internal storage if necessary.
If you haven't granted storage permissions yet, open Termux and run the following command to allow file access:
termux-setup-storage
A popup prompt will appear on your Android screen. Tap Allow to grant storage permissions to Termux.
Step 1: Update and Upgrade Termux Package Repositories
Before installing new packages, it is critical to update the package lists and upgrade existing software to their latest versions. Running outdated core packages can lead to broken dependency issues during installation.
Execute the following combined update and upgrade command in your terminal:
pkg update && pkg upgrade -y
If prompted about overriding configuration files during the package upgrade process, press Enter to accept the default options.
Step 2: Install Git in Termux
Now that your system repositories are fully updated, you can run the command to install git termux tools automatically. Termux uses its native package manager pkg (which acts as a wrapper for apt) to handle package binaries.
To start the Git installation, enter this command:
pkg install git -y
Termux will now download the Git package along with its necessary dependencies, such as OpenSSL and cURL. Once the installation process completes, verify that Git was installed properly by checking its version number:
git --version
You should see terminal output similar to this:
git version 2.43.0
Step 3: Configure Your Git Global Identity
Before you make commits or interact with services like GitHub, GitLab, or Bitbucket, you must configure your global identity details. Git attaches this metadata to every commit you make.
Run the following commands, replacing the placeholder values with your actual name and email address:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
To confirm that your global configuration details were correctly stored, execute:
git config --list
Step 4: How to Clone a Public Git Repository
With Git installed and configured, you are ready to download source code from remote repositories. Cloning creates a local copy of a remote project inside your current working directory.
To clone a public repository via HTTPS, copy the repository URL and pass it to the git clone command:
git clone https://github.com/octocat/Hello-World.git
After running the command, navigate inside the newly created directory using the cd command:
cd Hello-World
ls -la
Here is an illustration of what your terminal output looks like during a successful repository cloning operation:

Cloning into 'Hello-World'...
remote: Enumerating objects: 13, done.
remote: Total 13 (delta 0), reused 0 (delta 0), pack-reused 13
Unpacking objects: 100% (13/13), 2.25 KiB | 229.00 KiB/s, done.
Step 5: Termux Git Clone Private Repo (Authentication Setup)
Cloning a public project requires no authentication, but accessing a restricted codebase demands explicit authorization. When performing a termux git clone private repo request, GitHub and other providers no longer accept account account passwords over HTTPS for security reasons. Instead, you must authenticate using a Personal Access Token (PAT) or an SSH Key.
Method 1: Cloning Private Repos Using a Personal Access Token (PAT)
To use a Personal Access Token on GitHub, follow these quick steps:
- Log into your GitHub account on a web browser and go to Settings > Developer Settings > Personal Access Tokens > Tokens (classic).
- Click Generate new token, give it a description, and select the
reposcope permission. - Copy the generated token string immediately.
Now, execute the termux git clone private repo command by embedding your PAT into the URL structure:
git clone https://YOUR_GITHUB_USERNAME:YOUR_PERSONAL_ACCESS_TOKEN@github.com/username/private-repo.git
Alternatively, run the standard clone command and enter your token into the terminal password prompt when requested:
git clone https://github.com/username/private-repo.git
Username for 'https://github.com': YOUR_USERNAME
Password for 'https://YOUR_USERNAME@github.com': YOUR_PERSONAL_ACCESS_TOKEN
Method 2: Cloning Private Repos Using SSH Keys (Recommended)
The safest and most convenient way to handle authentication long-term is by setting up OpenSSH inside Termux.
1. Install the OpenSSH package in Termux:
pkg install openssh -y
2. Generate a new SSH key pair:
ssh-keygen -t ed25519 -C "your.email@example.com"
Press Enter to save the key to the default file location, and optionally enter a passphrase.
3. Output your public key to the terminal screen and copy it:
cat ~/.ssh/id_ed25519.pub
4. Go to GitHub Settings > SSH and GPG Keys > New SSH Key, paste your public key, and save it.
5. Now, you can perform your termux git clone private repo request using the SSH address without typing credentials every time:
git clone git@github.com:username/private-repo.git
Troubleshooting Common Termux Git Errors
Even simple installations can occasionally encounter issues. Below are common errors encountered when using Git inside Termux and how to resolve them quickly.
Error 1: fatal: destination path 'repo' already exists and is not an empty directory
Cause: You are attempting to clone a repository into a folder that already contains a directory with the same name.
Fix: Delete the existing directory or specify a target folder name at the end of your clone command:
git clone https://github.com/octocat/Hello-World.git my-new-folder
Error 2: remote: Support for password authentication was removed on August 13, 2021
Cause: You entered your regular GitHub account password instead of a Personal Access Token during HTTPS authentication.
Fix: Generate a Personal Access Token as outlined in Step 5, or switch your repository remote address to use SSH instead of HTTPS.
Error 3: fatal: unable to access '...': Could not resolve host
Cause: Loss of internet connection, DNS failure inside Termux, or an incorrect repository URL.
Fix: Test your internet connection by running ping google.com. If DNS resolution fails inside Termux, change your network connection or restart the Termux app.
What to Do Next
Now that you have successfully learned how to install git termux systems depend on and handle repository management, you are ready to build a full mobile development workflow.
Check out our step-by-step guide on How to Install Python in Termux and Run Your First Script to start building software projects right from your smartphone.
Join the conversation