Ctrl K

Git Workflow for Local Mirror Repositories

A fully local Git workflow using a bare .git directory as the central remote, with no dependency on any external hosting.

This setup keeps a local .git directory as the central remote, clones working copies from it, and uses standard push/pull operations against that local source. In this way GitHub repositories can be copied fully and managed locally as well.

Acquiring the .git

The central bare repository can come from two places. Mirror it directly from a remote host to get a complete local copy of all branches, tags, and refs or convert an existing bundle file into a live bare repository if no remote is available.

From a remote (GitHub or any Git host):

git clone --mirror https://github.com/user/project_name.git project_name.git

From a local bundle file:

git clone --bare project_name.bundle project_name.git

Both produce a project_name.git directory that works identically as a local remote. The --mirror form also copies remote refs and is preferred when a live remote exists.

Daily workflow

Clone from the central bare repository to create a working copy, then use Git as normal from inside it.

git clone /path/to/project_name.git
cd project_name

git add .
git commit -m "message"
git push
git pull

Inspect remote

Verify where the working repository points before pushing or pulling. The output shows both fetch and push targets.

git remote -v
# origin  /path/to/project_name.git (fetch)
# origin  /path/to/project_name.git (push)

Change remote path

If the central repository has moved, or the working copy still points to an old bundle path, update the remote URL and verify.

git remote set-url origin /new/path/to/project_name.git
git remote -v

Branch operations

Check local and remote branches, then push a new branch with upstream tracking so future pushes need no arguments.

git branch                     # local branches
git branch -a                  # all branches including remote
git branch --show-current      # active branch

git push -u origin branch_name # push and set upstream

Inspect central repo

Run this inside the bare .git directory to see every branch, tag, and ref it holds.

cd /path/to/project_name.git
git show-ref