Apply .gitignore on an existing repository already tracking large number of files
This answer solved my problem:
First of all, commit all pending changes.
Then run this command:
git rm -r --cached .
This removes everything from the index, then just run:
git add .
Commit it:
git commit -m ".gitignore is now working"
Create a .gitignore file, so to do that, you just create any blank .txt file.
Then you have to change its name writing the following line on the cmd (where
git.txt
is the name of the file you've just created):rename git.txt .gitignore
Then you can open the file and write all the untracked files you want to ignore for good. For example, mine looks like this:
```
OS junk files
[Tt]humbs.db
*.DS_Store
#Visual Studio files
*.[Oo]bj
*.user
*.aps
*.pch
*.vspscc
*.vssscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.[Cc]ache
*.ilk
*.log
*.lib
*.sbr
*.sdf
*.pyc
*.xml
ipch/
obj/
[Bb]in
[Dd]ebug*/
[Rr]elease*/
Ankh.NoLoad
#Tooling
_ReSharper*/
*.resharper
[Tt]est[Rr]esult*
#Project files
[Bb]uild/
#Subversion files
.svn
# Office Temp Files
~$*
There's a whole collection of useful .gitignore files by GitHub
Once you have this, you need to add it to your git repository just like any other file, only it has to be in the root of the repository.
Then in your terminal you have to write the following line:
git config --global core.excludesfile ~/.gitignore_global
From oficial doc:
You can also create a global .gitignore file, which is a list of rules for ignoring files in every Git repository on your computer. For example, you might create the file at ~/.gitignore_global and add some rules to it.
Open Terminal. Run the following command in your terminal: git config --global core.excludesfile ~/.gitignore_global
If the respository already exists then you have to run these commands:
git rm -r --cached .
git add .
git commit -m ".gitignore is now working"
If the step 2 doesn´t work then you should write the hole route of the files that you would like to add.
As specified here You can update the index:
git update-index --assume-unchanged /path/to/file
By doing this, the files will not show up in git status
or git diff
.
To begin tracking the files again you can run:
git update-index --no-assume-unchanged /path/to/file