Git refspecs and repository mirroring quick reference¶
One-page command matrix for refspecs, pull request fetching, dual-push configurations, and mirror replication.
1. Quick command matrix¶
| Task | Command |
|---|---|
| Fetch all remote branches | git fetch origin '+refs/heads/*:refs/remotes/origin/*' |
| Fetch specific PR locally | git fetch origin refs/pull/<id>/head:pr-<id> |
| Fetch all Forgejo/GitHub PRs | git config --add remote.origin.fetch '+refs/pull/*/head:refs/remotes/origin/pr/*' |
| Fetch all GitLab MRs | git config --add remote.origin.fetch '+refs/merge-requests/*/head:refs/remotes/origin/mr/*' |
| Push to multiple remotes | git config --add remote.origin.pushurl <url2> |
| Full mirror clone | git clone --mirror <url> <repo>.git |
| Atomic mirror push | git push --prune --atomic <remote> '+refs/*:refs/*' |
| Prune stale tracking branches | git fetch --prune origin |
| Sync Git LFS objects across mirrors | git lfs fetch --all origin && git lfs push --all backup |
2. Refspec syntax patterns¶
+refs/heads/*:refs/remotes/origin/*: Force update all tracking branches.refs/tags/*:refs/tags/*: Synchronize all tags without forcing overwrites.+refs/tags/*:refs/tags/*: Synchronize all tags and overwrite modified tags.^refs/heads/feature/*: Exclude feature branches from fetch (Git 2.29+).+refs/notes/*:refs/notes/*: Synchronize Git notes.
3. Dual-push configuration snippet¶
Add secondary destination URLs to push to multiple hosts with a single command:
git remote set-url --add --push origin git@git.local.sneakysquid.xyz:hermes/repo.git
git remote set-url --add --push origin git@github.com:sneakysquid/repo.git
Verify configured URLs:
4. Disaster recovery sync recipe¶
Run on a CI runner to replicate from primary forge to backup forge: