Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lysander6/e2cf0a591fc5de50ac19cd7c9a24fed0 to your computer and use it in GitHub Desktop.
Save Lysander6/e2cf0a591fc5de50ac19cd7c9a24fed0 to your computer and use it in GitHub Desktop.
Using rsync with .gitignore files
#
# Rsync a git repository without .git directory, excluding files as per .gitignore
# -- as if, the target directory is a checkout without .git directory.
#
rsync -azP --delete --delete-excluded --filter=":- .gitignore" --exclude .git/ src/dir/path/ user@host:/dst/dir/path/
#
# Rsync a git repository including the .git directory, excluding files as per
# .gitignore -- as if, the target directory is a clone.
#
rsync -azP --delete --filter=":- .gitignore" src/dir/path/ user@host:/dst/dir/path/
# NOTES
#
# Rsync behaves differently if source and target paths end with '/' character or not.
# Above commands can be run repeatedly so that Rsync repeatedly syncs same directories
# without creating a new copy as a subdirectory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment