I recently embarked on a green field application and in my haste to get things up and running I forgot to add a .gitignore to my solution. Not a big issue, until you factor in that I only realised this about a dozen commits in!
Thankfully, this was a fairly simple thing to fix and for those in the same boat; here's how I went about it...
Step 1
First of all, add your .gitignore to your solution and commit it.
Step 2
Next, remove everything from the repo (don't panic, your files won't be deleted!) by using the bash command git rm -r --cached .
-
rm
is the remove command -
-r
will allow recursive removal -
--cached
will only remove files from the index and won't delete your files. - the
.
at the end means that all files will be untracked. If you want to untrack a specific file, use the commandgit rm --cached filename.txt
.
Step 3
Once you've removed and untracked your files, you can now add your files with git add .
then re-commit everything with your .gitignore git commit -m "added .gitignore"
and push.
And thats it, you will now have a clean repo π
Top comments (0)