{"action":"created","issue":{"url":"https://api.github.com/repos/github/git-lfs/issues/326","labels_url":"https://api.github.com/repos/github/git-lfs/issues/326/labels{/name}","comments_url":"https://api.github.com/repos/github/git-lfs/issues/326/comments","events_url":"https://api.github.com/repos/github/git-lfs/issues/326/events","html_url":"https://github.com/github/git-lfs/issues/326","id":79508384,"number":326,"title":"Best practice for migrating an existing Git repo to support LFS?","user":{"login":"strich","id":987896,"avatar_url":"https://avatars.githubusercontent.com/u/987896?v=3","gravatar_id":"","url":"https://api.github.com/users/strich","html_url":"https://github.com/strich","followers_url":"https://api.github.com/users/strich/followers","following_url":"https://api.github.com/users/strich/following{/other_user}","gists_url":"https://api.github.com/users/strich/gists{/gist_id}","starred_url":"https://api.github.com/users/strich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/strich/subscriptions","organizations_url":"https://api.github.com/users/strich/orgs","repos_url":"https://api.github.com/users/strich/repos","events_url":"https://api.github.com/users/strich/events{/privacy}","received_events_url":"https://api.github.com/users/strich/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":21,"created_at":"2015-05-22T16:00:13Z","updated_at":"2015-11-27T19:57:02Z","closed_at":null,"body":"I'd like to give Git LFS a good crack with our existing ~25GB Git repo but I'm at a bit of a loss as to how we should go about migrating it to support LFS.\r\nI'm happy to loose all history of the existing large files I'd like to track with LFS.\r\n\r\nDo I need to write a script to find and purge all the filetypes I want to track with LFS from the existing Git history, untrack them, then retrack them with LFS?"},"comment":{"url":"https://api.github.com/repos/github/git-lfs/issues/comments/160196400","html_url":"https://github.com/github/git-lfs/issues/326#issuecomment-160196400","issue_url":"https://api.github.com/repos/github/git-lfs/issues/326","id":160196400,"user":{"login":"kalibyrn","id":619806,"avatar_url":"https://avatars.githubusercontent.com/u/619806?v=3","gravatar_id":"","url":"https://api.github.com/users/kalibyrn","html_url":"https://github.com/kalibyrn","followers_url":"https://api.github.com/users/kalibyrn/followers","following_url":"https://api.github.com/users/kalibyrn/following{/other_user}","gists_url":"https://api.github.com/users/kalibyrn/gists{/gist_id}","starred_url":"https://api.github.com/users/kalibyrn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kalibyrn/subscriptions","organizations_url":"https://api.github.com/users/kalibyrn/orgs","repos_url":"https://api.github.com/users/kalibyrn/repos","events_url":"https://api.github.com/users/kalibyrn/events{/privacy}","received_events_url":"https://api.github.com/users/kalibyrn/received_events","type":"User","site_admin":false},"created_at":"2015-11-27T19:57:02Z","updated_at":"2015-11-27T19:57:02Z","body":"I hope I'm not beating a dead horse, but..\r\n\r\nThis little script is still probably slower than bfg, but I couldn't figure out how to get bfg to honor my lfs remote location.  So, I wanted to build on the work from @andyneff and @vmrob and make the filter-branch commands they provided faster.\r\n\r\n```bash\r\ngit filter-branch --prune-empty --tree-filter '\r\ngit config -f .gitconfig lfs.url \"http://artifactory.local:8081/artifactory/api/lfs/git-lfs\"\r\ngit lfs track \"*.exe\" \"*.gz\" \"*.msi\" \"*.pdf\" \"*.ppt\" \"*.pptx\" \"*.rar\" \"*.vdx\" \"*.vsd\" \"*.war\" \"*.xls\" \"*.xlsm\" \"*.xlsx\" \"*.zip\" > /dev/null\r\ngit add .gitattributes .gitconfig\r\ngit ls-files | xargs -d \"\\n\" git check-attr filter | grep \"filter: lfs\" | sed -r \"s/(.*): filter: lfs/\\1/\" | xargs -d \"\\n\" -r -n 50 bash -c \"git rm -f --cached \\\"\\$@\\\"; git add \\\"\\$@\\\"\" bash \\\r\n' --tag-name-filter cat -- --all\r\n```\r\nBy combining the \"git lfs track\" line into one and by using \"xargs -n 50\" I was able to cut down on invoking git by more than 50 times per revision, in my case. (Way too many binaries in our repository!)  That made things FAR faster...  It handles spaces in the filenames also.\r\n\r\nIt seems to be working on Linux, but I can't comment on whether it would work for Mac OS X."}}