Git reset and rsync are two tools that, combined, can cut through the mess. Git reset rewinds your local repository to a clean state. Rsync moves files with surgical precision to match that state across environments. Done correctly, you can wipe away bad commits, restore the right files, and deploy without dragging old mistakes along.
Why Git Reset Matters
git reset --hard clears your working directory and index, forcing everything to match a specific commit. Use it to roll back to a stable point before a failed merge, bad code push, or accidental file change. Pair it with git fetch to reset to origin/master or any branch that holds your known-good code.
Why Rsync Fits
Rsync is fast, incremental, and reliable. It syncs files from one location to another based on checksums and modification times. For repos, it’s the fastest way to mirror your git-reset state to servers, CI workspaces, or development machines. Common command:
rsync -av --delete ./ target-server:/path/to/deploy/
The --delete flag ensures removed files are also removed remotely, keeping your live code clean.