Skip to content

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 ​

TaskCommand
Fetch all remote branchesgit fetch origin '+refs/heads/*:refs/remotes/origin/*'
Fetch specific PR locallygit fetch origin refs/pull/<id>/head:pr-<id>
Fetch all Forgejo/GitHub PRsgit config --add remote.origin.fetch '+refs/pull/*/head:refs/remotes/origin/pr/*'
Fetch all GitLab MRsgit config --add remote.origin.fetch '+refs/merge-requests/*/head:refs/remotes/origin/mr/*'
Push to multiple remotesgit config --add remote.origin.pushurl <url2>
Full mirror clonegit clone --mirror <url> <repo>.git
Atomic mirror pushgit push --prune --atomic <remote> '+refs/*:refs/*'
Prune stale tracking branchesgit fetch --prune origin
Sync Git LFS objects across mirrorsgit lfs fetch --all origin && git lfs push --all backup

2. Refspec syntax patterns ​

[+]<source-pattern>:<destination-pattern>
  • +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:

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

bash
git remote -v

4. Disaster recovery sync recipe ​

Run on a CI runner to replicate from primary forge to backup forge:

bash
# 1. Update local mirror cache
git fetch --prune origin '+refs/*:refs/*'

# 2. Push all branches, tags, and refs atomically
git push --prune --atomic backup '+refs/*:refs/*'

# 3. Synchronize LFS payloads
git lfs fetch --all origin
git lfs push --all backup

Git Master — Git Reference for Every Skill Level