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.
Acquiring the .git
Section titled “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.gitFrom a local bundle file:
git clone --bare project_name.bundle project_name.gitBoth 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
Section titled “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.gitcd project_name
git add .git commit -m "message"git pushgit pullInspect remote
Section titled “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
Section titled “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.gitgit remote -vBranch operations
Section titled “Branch operations”Check local and remote branches, then push a new branch with upstream tracking so future pushes need no arguments.
git branch # local branchesgit branch -a # all branches including remotegit branch --show-current # active branch
git push -u origin branch_name # push and set upstreamInspect central repo
Section titled “Inspect central repo”Run this inside the bare .git directory to see every branch, tag, and ref it holds.
cd /path/to/project_name.gitgit show-ref