Search code examples
gitgitignore

gitignore for git add


I want gitignore a file that is already committed and pushed to master;

Meaning, I want to ignore any change of that file.

But after I add the path in gitignore, it is still included in commit and pushed when I use

git add .

how do I ignore such file ?


Solution

    1. If you want the file to be removed altogether, you can delete the file locally, commit and push to master.

    Remember, gitignore will only work for files, not yet pushed to remote. If already pushed to remote then, it will not work.

    A gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected

    1. If you want to keep the file in master and ignore only your local changes, you can update git exclude file located in $GIT_DIR/info/exclude.

    Read more information on gitignore

    Read more information on ignore files locally in this stackoverflow Q&A