I didn't encounter Git until the end of high school and it wasn't until a few years later that I actually understood how to use it properly. One of the biggest things I missed was the power of
.gitignore. This lead to many wayward
gen/ commits and unnecessarily large repositories.
Fast forward to the present predicament: bulk cleaning of past commits.
.gitignorefile you should have way back when.
Github .gitignore Collection
Base OS .gitignore Sample
Apply the new
.gitignorerules to all commits:
git filter-branch --force --index-filter \ 'git ls-files -ci --exclude-from=/path/to/repository/.gitignore -z | xargs -0 git rm --cached' \ --prune-empty --tag-name-filter cat -- --allIf Git does not allow you to use the
.gitignorefile from within the repository then you will need to copy it into a different directory, update the path in the sample, and re-run it.
See Reference section below for details on the above code sample
Overwrite remote repository:
git push origin --force --all
- [Optional] Add Git alias to apply
.gitignorechanges in the future
Open Git configuration file
aliassection does not exist, you will need to add it.
[alias] apply-gitignore = !git ls-files -ci --exclude-standard -z | xargs -0r git rm --cachedSave your changes