Termux Git Commands

Install Git

pkg update && pkg upgrade
pkg install git unzip openssh
Git
Tracks code changes
Unzip
Extracts zip files
OpenSSH
Enables secure SSH connections

Initialize A Repository

git init

Configuration

git config --global user.name "Your Name"
git config --global user.email "your_email@example.com"
git config --list
git config --global
  • First-time setup
  • Only when changing
git config --list
Check

Local Copy Of Remote Repo

git clone <repository-URL>
git clone git@github.com:username/repo.git
git clone <repository-URL> my-folder

What To Do After Cloning

  • Go into the repo folder:
    cd repo
  • Check or switch branches if needed:
    git branch
    git checkout feature-branch
  • Edit files → stage → commit → push:
    git add .
    git commit -m "My changes"
    git push

Remote Repository Management

HTTPS (Easy Setup)

git remote add origin https://github.com/username/repo.git
  • First auth requires username + PAT, then cached
  • Generate token: GitHub → Settings → Developer settings → Personal Access Tokens

SSH (Secure & Convenient)

Step 1: Generate SSH Key In Termux

ssh-keygen -t ed25519 -C "your_email@example.com"
Private key
~/.ssh/id_ed25519
Public key
~/.ssh/id_ed25519.pub
  • Enter file in which to save the key:
    → Press Enter (default)
  • Enter passphrase:
    → Type one or press Enter (none)

Step 2: Add Public Key To GitHub

cat ~/.ssh/id_ed25519.pub
chmod 600 ~/.ssh/id_ed25519
  • Copy the output
  • GitHub → Settings → SSH and GPG keys → New SSH key → Paste
chmod 600 ~/.ssh/id_ed25519
Permission

Step 3: Test Connection

ssh -T git@github.com
  • Success message: Hi username! You've successfully authenticated…

Step 4: Add Remote Using SSH URL

git remote add origin git@github.com:username/repo.git

Choosing Between HTTPS And SSH

  • HTTPS
    • Quick & easy
    • Good for temporary use or public computers
  • SSH
    • Best for frequent work
    • Great for automation, scripts, and Termux Widgets

Change Remote URL

git remote set-url remote_name newURL

Remove Remote

git remote remove remote_name

List Remote

git remote -v

Branch Management

List Branches

git branch

Create A New Branch

git branch branch_name

Switch Branch

git checkout branch_name
git switch branch_name
  • checkout or switch

Create & Switch In One Step

git checkout -b new_branch

Merge To main Branch

git checkout main
git merge branch_name

Renames The Current Branch

git branch -m new-name
git branch -M new-name
git branch -m new-name
Fails if a branch with the new name already exists
git branch -M new-name
Overwrites the target branch if it already exists

Delete Branch

git branch -d branch_name
git branch -D branch_name
git branch -d branch_name
This works only if the branch has already been merged
git branch -D branch_name
Deletes the branch even if it hasn’t been merged

Stage Files

git add filename
git add .
git reset
git reset file
git add .
. stages all changes
git reset
Unstage added files

Commit Changes

git commit -m "Commit message"
git commit --allow-empty -m "Commit message"
git log
--allow-empty
Creates a commit with no changes
git log
View history

Check Status

git status
  1. Before starting work
    • Check which files have been modified or are untracked
      → Helps you see “Do I need to commit this file?”
  2. After git add
    • Verify which files are staged
      → Shows “Which files will be included in the next commit?”
  3. Before committing
    • Double-check which changes are not yet committed to avoid missing anything
  4. During work
    • If you’re editing multiple files, use it to keep track of your changes and stay organized

Fetch & Merge

git pull remote_name branch_name
git pull origin main --rebase
git pull origin main --rebase
Apply your commits after the remote commits

Conflict

When two changes edit the same part, you must fix it manually.

Check What’s Conflicted

git status
  • Files marked “both modified” need to be fixed

Open The Conflicted File

<<<<<<< HEAD
your changes
=======
incoming changes
>>>>>>> origin/main
  • <<<<<<< HEAD → your local changes
  • ======= → separator
  • >>>>>>> origin/main → changes from remote

Resolve A Git Conflict

nano
git checkout --theirs .
git checkout --ours .
nano
Resolve the conflict manually
git checkout --theirs .
Use the remote version
git checkout --ours .
Keep the local version
  • Delete the conflict markers (<<<<<<<, =======, >>>>>>>) after editing manually
  • In rebase, ours and theirs are swapped

After Fixing The File

git add .
git rebase --continue
git add .
git commit
git rebase --continue
  • Using sit status
  • rebase in progress
git commit
  • Using git status
  • You are in the middle of a merge

How To Confirm It’s Fully Done

git status

If you see:

  • nothing to commit
  • working tree clean

👉 That means the merge is complete and the conflict is over

Push To Remote

git push remote_name branch_name
git push -u origin main
git push
git push -u origin main
First time(Link the local branch to the remote branch)
git push
Second time

Overwrite

git push --force
git push --force-with-lease
git push -f
git push --force
Overwrites the remote branch
git push --force-with-lease
Overwrites only if the remote hasn’t changed
git push -f
-f = --force

How To Deploy (Step By Step)

First Deploy To GitHub

cd project
git init
git config --global user.name "Lanlanwi"
git config --global user.email "example@gmail.com"
git remote add origin URL
git branch -M main
git add .
git commit -m "first commit"
git pull origin main --rebase
git push -u origin main
  1. git init
  2. git config
  3. git remote
  4. git branch
  5. git add
  6. git commit
  7. git pull
  8. git push

Next Deployment

git add .
git commit -m "update"
git pull
git push
  1. git add
  2. git commit
  3. git pull
  4. git push

Change Remote URL And Deploy

git remote set-url origin URL
git add .
git commit -m "update"
git pull origin main --rebase
git push -u origin main
  1. git remote
  2. git add
  3. git commit
  4. git pull
  5. git push

Force Push (Overwrite Remote)

git add .
git commit -m "update (force push)"
git push --force
  1. git add
  2. git commit
  3. git push

Empty The Remote Repository

git reset
git commit --allow-empty -m "clear"
git push origin main --force
  1. git reset
  2. git commit
  3. git push