Tim Habersack

Where I put my things..

Using your .gitignore as your rsync filter

Feb 21st 2019

This is always pesky. You have a project and you're using #git as your version control. You have a well manicured .gitignore file to handle certain things out of your repo.

But! then you need to push everything via #rsync somewhere. Maybe that's your deploy strategy, I don't know. I'm not a doctor. I do know that using the rsync --exclude to call out each single directory and file you don't want pushed over is a super pain. And you already have this .gitignore just sitting there, that holds that kind of list already!

Enter --filter.

If you do something like:

rsync -avz --filter=':- .gitignore' dir/ user@server:/path/to/destination

It will only push over the items that your .gitignore would allow to be pushed up to your repo. Excellent, yes?