Skip to content

Git Workflow for Local Mirror Repositories

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.

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):

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

From a local bundle file:

Terminal window
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.

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

Terminal window
git clone /path/to/project_name.git
cd project_name
git add .
git commit -m "message"
git push
git pull

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

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

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

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

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

Terminal window
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

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

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