Git: Ignore files that have already been committed to a Git repository


Step 1: update file .gitignore

Step 2:
git rm -r --cached .

Step 3:
git add .

Result:

$ git add .
warning: LF will be replaced by CRLF in composer.json.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in composer.lock.
The file will have its original line endings in your working directory.

Step 4: Commit it:
git commit -m "add .gitignore"

Result:

$ git commit -m "add .gitignore"
[master 5e7d42e] add .gitignore
 950 files changed, 177570 deletions(-)
 delete mode 100644 .bash_history
...

Step 5:
git push

Result:

$ git push
Counting objects: 2, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 221 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/sansamour/phpMoAdmin-MongoDB-Admin-Tool-for-PHP
   8c7e959..5e7d42e  master -> master

Leave a Reply