This guide explains how to host a Git repository on an Android phone (using Termux) and set it up as a remote to sync multiple computers.
- An Android phone with Termux installed (preferably from F-Droid).
- Git installed on Termux and on your computers.
- A local network (hotspot or USB tethering) to connect computers to the phone.
pkg update && pkg upgrade
pkg install git opensshmkdir -p ~/git/<repo-name>.git
cd ~/git/<repo-name>.git
git init --baresshd
passwd # Set a password if not already doneifconfig- Look for the
swwlan0(hotspot) orv4-rmnet0(USB tethering) interface. - Note the IP address (e.g.,
192.168.43.1or10.226.x.x).
git remote add phone ssh://<phone-ip>:8022/~/git/<repo-name>.gitReplace <phone-ip> with the IP address found earlier.
git remote -vYou should see phone listed among the remotes.
git push phone <branch-name>Replace <branch-name> with master, main, or your branch name.
git pull phone <branch-name>| Issue | Solution |
|---|---|
git-receive-pack: command not found |
Ensure Git is installed on Termux (pkg install git). |
| Unable to connect via SSH | Ensure sshd is running and the IP is correct. |
| Branch does not exist | Create the branch locally (git checkout -b <branch-name>) and push it. |
| SSH password prompt every time | Set up an SSH key to avoid entering the password. |
| ssh: connect to host x port y: Connection refused | Make sure you have launched the ssh server with sshd in termux to be able to push changes. |
| Terminal remains static when pushing changes | Check the phone's ip address with the ifconfig command in termux. If the ip address has changed, set the new URL with git remote set-url phone ssh://<phone-ip>:8022/~/git/<repo-name>.git |
- Use a script to automate
git pushandgit pullwhen the phone is connected. - Set up Git hooks to trigger actions after push/pull.
- Use a strong password for SSH.
- Disable hotspot or USB tethering when not in use.
- Do not share your Git repository over an unsecured network.