This guide explains how to manage Git and GitHub entirely from Termux on Android. It is designed to be clean, professional, and copy‑paste friendly. Every command is written in separate blocks so you can copy them one by one.
pkg update && pkg upgrade -y
pkg install git -y
termux-setup-storageExplanation:
- Updates Termux packages.
- Installs Git.
- Grants Termux access to your phone storage.
git config --global user.name "your-github-username"
git config --global user.email "your-github-email"Explanation:
This sets your GitHub username and email for commits.
Go to your project folder (example: crosshair) and run:
cd /storage/emulated/0/Download/crosshair
git init
git branch -M mainExplanation:
git initstarts a new repository.git branch -M mainrenames the default branch tomain.
git remote add origin https://github.com/your-username/your-repo.gitExplanation:
Links your local project with the GitHub repository.
If you get an error remote origin already exists, reset it:
git remote remove origin
git remote add origin https://github.com/your-username/your-repo.gitgit add .
git commit -m "Initial upload"Explanation:
git add .stages all files.git commit -msaves the changes locally.
git push -u origin maingit pull origin main --allow-unrelated-histories
git push origin maingit push origin main --forcegit clone https://github.com/your-username/your-repo.gitExplanation:
Downloads a GitHub repo to Termux.
git pull origin mainExplanation:
Fetches and merges latest changes from GitHub.
To remove and set a new remote:
git remote remove origin
git remote add origin https://github.com/your-username/new-repo.gitIf you want to delete all Git settings and start fresh:
rm -rf .git
git init
git branch -M main
git remote add origin https://github.com/your-username/your-repo.gitgit clone https://github.com/your-username/your-repo.gitgit clone git@github.com:your-username/your-repo.gitTo generate SSH key in Termux:
ssh-keygen -t rsa -b 4096 -C "your-email@example.com"
cat ~/.ssh/id_rsa.pubCopy the output and add it to your GitHub SSH keys.
- Fork the repository on GitHub.
- Clone your fork in Termux.
- Create a new branch:
git checkout -b feature-branch- Make changes and commit:
git add .
git commit -m "Added new feature"- Push branch:
git push origin feature-branch- Open GitHub website → Create Pull Request.
-
Error:
remote origin already exists
Fix:git remote remove origin git remote add origin https://github.com/your-username/your-repo.git
-
Error:
failed to push some refs
Fix (merge with remote):git pull origin main --allow-unrelated-histories git push origin main
Fix (overwrite remote):
git push origin main --force
-
Error:
Reinitialized existing Git repository
Fix:rm -rf .git git init
With these commands, you can fully manage Git and GitHub from Termux — including repository setup, uploads, replacements, pull requests, and error handling.