Skip to content

Instantly share code, notes, and snippets.

@bvk
Created January 24, 2019 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bvk/236de6fe34019ed8ccbe75a11379b454 to your computer and use it in GitHub Desktop.
Save bvk/236de6fe34019ed8ccbe75a11379b454 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