Sometimes it’s really frustrating to try to remove a file or a folder in a git working repository, but it seems that our configuration doesn't work at all.
Even more, it can lead to us pushing a wrong file to code reviewers, and that’s not professional at all.
So, to fix this problem, I decided to write this easy-to-follow, blog post on how you can ignore a file or a folder using the .gitignore
file.
First thing first, you will need to tell Git not to track this file or folder by removing it from the index.
(you can add the -f
option to force the git remove command)
The git rm
command, along with the --cached
option, deletes the file from the repository but does not delete the actual file. This means the file remains on your local system and in your working directory as an ignored file.
Once this step above has been done, you can add the file to .gitignore
# The file or directory you want to ignore
/path/to/your/file
A git status
will show that the file is no longer in the repository, and entering the ls
command will show that the file exists on your local file system.
That’s it, your file has been ignored.
I hope you enjoyed reading this, and I'm curious to hear if this tutorial helped you. Please let me know your thoughts below in the comments. Don't forget to subscribe to my newsletter to avoid missing my upcoming blog posts.
You can also find me here LinkedIn • Twitter • GitHub or Medium