How to apply gitignore afterwards?

I put my local repository on GitHub. In the process of executing my code, I forgot to create a file .gitignore. As a result, I committed and subsequently clicked on several folders and files that I donโ€™t need in GitHub (or in my local repository, for that matter).

How can I apply .gitignorenow so that I can delete some unwanted folders and files in the future?

+5
source share
4 answers

You can git rm <unnecessary file and folder names>then add them to your .gitignorefile, which will remove them from this message. The problem is that they will remain in history unless you change earlier commits. If there is no sensitive data in these files, I would say leave the history as it is. If you need to remove sensitive data from the history of your repository, see the GitHub help article on this.

+6
source

First, delete the directory binadded to the repo by accident. You can contact here: http://help.github.com/remove-sensitive-data/

Then add .gitignoreand commit, and then click on github.

+3
source

You must delete it from memory and add it again. Git is ignored.

Answered already?

+2
source

If this is your personal repo and you have not published it yet, use it filter-branchto edit the story:

git filter-branch --index-filter '
  git rm -r --cached --ignore-unmatched bin;
' --all

Then add / edit the file .gitignore:

>> .gitignore echo bin
git add .gitignore
git commit -m 'add gitignore files'

Since you have already published your story, itโ€™s best not to rewrite it. Just delete the bin directory and add the .gitignore file

git rm -r bin
# add .gitignore
git commit -m 'remove and ignore bin folder'
+2
source

All Articles