Skip to content

Instantly share code, notes, and snippets.

@loursblancgithub
Last active January 6, 2026 08:30
Show Gist options
  • Select an option

  • Save loursblancgithub/0c0ad4cc976db2a0ab2d1e2029a18819 to your computer and use it in GitHub Desktop.

Select an option

Save loursblancgithub/0c0ad4cc976db2a0ab2d1e2029a18819 to your computer and use it in GitHub Desktop.
Using an Android Phone as a Portable Git Server

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.


Prerequisites

  • 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.

1. Setting Up the Phone as a Git Server

1.1. Install Git and SSH on Termux

pkg update && pkg upgrade
pkg install git openssh

1.2. Create a Bare Git Repository

mkdir -p ~/git/<repo-name>.git
cd ~/git/<repo-name>.git
git init --bare

1.3. Start the SSH Server

sshd
passwd  # Set a password if not already done

1.4. Find the Phone's IP Address

ifconfig
  • Look for the swwlan0 (hotspot) or v4-rmnet0 (USB tethering) interface.
  • Note the IP address (e.g., 192.168.43.1 or 10.226.x.x).

2. Setting Up Computers

2.1. Add the Phone as a Remote

git remote add phone ssh://<phone-ip>:8022/~/git/<repo-name>.git

Replace <phone-ip> with the IP address found earlier.

2.2. Verify the Remote

git remote -v

You should see phone listed among the remotes.


3. Syncing Changes

3.1. Push Changes to the Phone

git push phone <branch-name>

Replace <branch-name> with master, main, or your branch name.

3.2. Pull Changes from the Phone

git pull phone <branch-name>

4. Troubleshooting Common Issues

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

5. Automation (Optional)

  • Use a script to automate git push and git pull when the phone is connected.
  • Set up Git hooks to trigger actions after push/pull.

Security Notes

  • 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment