{
"$type": "site.standard.document",
"content": "---\ntitle: \"rclone: exclude all git repos\"\ndescription: \"A bash script to auto-exclude all git repos from rclone backups, since\n rclone's built-in filtering can't do it alone.\"\ntags:\n - dev\n---\n\nFor a long time I've used [rclone](https://rclone.org) for remote backups and\nit's awesome. I have a script which syncs all the files I care about on my\nlaptop to cloudstor, which, being on the Australian university network, has the\nbenefit that I get 1Gbps upload when I'm on the ANU network.\n\nHowever, it turns out that\n[cloudstor](https://support.aarnet.edu.au/hc/en-us/articles/5697089309711) is\nshutting down at the end of this year, so I need to find a new home for my\nbackups. I've been told that the \"replacement\" is to use my institutional\nOneDrive account.\n\nMy feelings about closing down useful (local) infrastructure and centralising\nthings on one of the big cloud providers notwithstanding, this should be an easy\nchange. [rclone supports OneDrive](https://rclone.org/onedrive/), so it's a\nsimple config change to move over.\n\nHowever, I figured I'd take the opportunity to fix something which had long\nbothered me. I have a _lot_ of stuff in git repos which don't need to be backed\nup with rclone, and they just slow down the backup process. I wanted to get\nrclone to ignore all git repos, and although it has an\n[include/exclude filtering](https://rclone.org/filtering/) system it's not easy\nto get it to filter all git repos (trust me,\n[I checked](https://forum.rclone.org/t/ignore-all-git-repos-when-syncing/33023)).\n\nNow that it's summertime I had a chance to make it work, and since that forum\nthread is now locked I'm posting it here to save you some time, dear reader, if\nyou ever want to do this for yourself. Feel free to use/modify it (MIT Licence)\nif it's helpful.\n\n```bash\n#!/bin/bash\n\nEXCLUDE_FROM_FILE=\"/tmp/rclone-excludes.txt\"\nCLONE_ROOT_DIR=~/Documents\nREMOTE=anu-onedrive\n\n## find all git repo enclosing folders (including trailing slash), munge them\n## into the form that rclone expects for its \"exclude from\" file\ncd $CLONE_ROOT_DIR && find . -type d -name .git -exec dirname {} \\; | sed -e 's/$/\\//' -e 's/^.//' > $EXCLUDE_FROM_FILE\n\n## add a few extra excludes\necho \".DS_Store\" >> $EXCLUDE_FROM_FILE\n\n## sync to remote\nrclone sync --progress --exclude-from=$EXCLUDE_FROM_FILE $CLONE_ROOT_DIR $REMOTE:mitch-rclone/$CLONE_ROOT_DIR\n```\n",
"createdAt": "2026-05-13T23:14:47.167Z",
"description": "A bash script to auto-exclude all git repos from rclone backups, since rclone's built-in filtering can't do it alone.",
"path": "/blog/2023/01/11/rclone-exclude-all-git-repos",
"publishedAt": "2023-01-11T00:00:00.000Z",
"site": "at://did:plc:tevykrhi4kibtsipzci76d76/site.standard.publication/self",
"tags": [
"dev"
],
"textContent": "A bash script to auto-exclude all git repos from rclone backups, since rclone's built-in filtering can't do it alone.",
"title": "rclone: exclude all git repos"
}