Git rsync is not a single command, but a workflow: use rsync’s efficient file transfer to push Git-tracked code between machines while keeping the repo intact. It’s faster than a full git clone when you already have a repo structure in place, and more reliable than scp when you care about incremental changes.
Why Combine Git and rsync
Git handles version control. Rsync handles file synchronization.
When developing or deploying, you can pair them to:
- Avoid re-downloading large binaries or dependencies
- Sync working directories without disturbing
.git metadata - Mirror repos to build servers, staging machines, or containers
Core Command Patterns
To sync a local Git repo to a remote host:
rsync -avz --delete ./ user@remote:/path/to/repo
The --delete flag ensures removals match between ends. The .git directory will remain untouched unless you explicitly exclude it.
To keep Git history out of deployment:
rsync -avz --exclude='.git' ./ user@remote:/path/to/deploy
This sends only the tracked content, ideal for production environments where you don’t need the repo itself.
Syncing Submodules
If your repo uses Git submodules, initialize and update them first:
git submodule update --init --recursive
Then sync with rsync so the remote has the fully populated dir tree.
- Add
--partial and --progress for visibility and resilience. - Use
--compress if network bandwidth is the bottleneck. - For large deployments, set up an rsync daemon on the destination to avoid repeated SSH overhead.
When to Use This Approach
- Rapid iteration across multiple development nodes
- Deploying code without full CI/CD
- Offline mirroring of repos for build farms
- Disaster recovery by syncing both sources and version metadata
Git rsync workflows save time and reduce risk. They give you precise control over what moves and when.
Want to take this beyond shell scripts and see automated, lightning-fast code sync with Git logic built in? Spin up a project on hoop.dev and watch it live in minutes.