Gitignore
Adding a .gitignore into an exiting repository
-
Create a .gitignore file within your repo using the touch command:
touch .gitignore
-
Commit all your pending changes using
-
Then run this command, which removes everything from index:
git rm -r --cached .
Note
The git rm command deletes files both from the Git repository as well as the filesystem. Using the cached flag, the actual file on disk will not be deleted.
-
Then just stage all the files again by running:
git add .
-
Next Commit the staged changes, using:
git commit -m ".gitignore is now working"
-
Finally push the commit to your repo:
git push origin /<master/branch_name/>
Caution
Please be careful, when you push this to a repository and pull from somewhere else into a state where those files are still tracked, the files will be DELETED.
References
Stackoverflow: Apply .gitignore on an existing repository already tracking large number of files