How to Check if gitignore is Working | Show Ignored Files
- Last Updated On: July 22, 2021
- By: Scriptcrunch Editorial
.gitignore file is a great way to disallow files from being committed to git public or private repositories.
In this blog, we will explain to you how to validate the .gitingnore file by listing the files using git check-ignore
command.
Git Show Ignored Files
Git has an inbuilt command named check-ignore to check if a file is ignored or not.
To validate the .gitignore file, first, we will look at an example .gitignore file. Also, you can take a look at the gitignore templates for reference.
*.log
*.secret
#ignore a specific file
/app/access.log
# Ignore the node_modules directory
node_modules/
# Ignore the build directory
/dist
# The file containing environment variables
.env
Now let’s look at different scenarios using the above .gitignore file as an
example.
List all git ignored file in a Repository
Execute the following command to check all the ignored files in a repository.
git check-ignore -v **/*
You will get an output with the rule and the file location as shown below.
List all git ignored file in a Directory
To check all the ignored files by git in the directory, first cd
into the directory.
Then execute the following command.
git check-ignore *
To show the ignore rule, add a -v
git check-ignore -v *
Check if a single File is ignored by git
Sometimes we might need to check if a single file is ignored by git.
To do this, execute the check-ignore command with the file path. It will output the file name if it is ignored by git.
For example,
git check-ignore app/access.log
Sample output,
➜ gitignore git:(master) ✗ git check-ignore app/access.log/
app/access.log/
Check git status
Another option to verify ignored files is by checking the git status. If you make changes, the files in the .gitignore
should not show up in the status.
fatal: no path specified Error [check-ignore]
When using the check-ignore
command, if you don’t specify a regular expression or a path with the command, it will throw no path specified Error
Either execute the command with a regular expression or add the directory or file path.
Scriptcrunch Editorial
Other Interesting Blogs
Best Black Friday Deals For Techies in 2024
In this blog, we have listed down all the best Black Friday deals and Cyber Monday deals for techies. This is the
[80% OFF] Linux Foundation Coupon for November 2024
Looking for CKA Coupon and other Linux Foundation certifications coupons? We got you covered. With the latest Linux Foundation Coupon, you can
[40% OFF] Linux Foundation LFCA, LFCS & LFCT Exam Voucher Codes
Linux Foundation has announced up to a $284 discount on its Linux certification programs Linux Foundation Certified IT Associate (LFCA) and Linux
1 thought on “How to Check if gitignore is Working | Show Ignored Files”
Very useful. Thanks for this article.