What is GItIgnore in Git?

Share via:

Dear Readers,

What is GItIgnore in Git?

In this article,we will see Create new files and ignore specific file while commiting.

Git Ignore

A gitignore file specifies intentionally untracked files that Git should ignore.

Files already tracked by Git are not affected.

Git can be configured to ignore certain files and directories for repository operations.

The file system of Git is classified into three categories

  • Tracked
  • Untracked
  • Ignored


Tracked files are such files that are previously staged or committed.


Untracked files are such files that are not previously staged or committed.


Ignored files are such files that are explicitly ignored by git. We have to tell git to ignore such files.

I am creating 4 files ktexperts.txt,ktexperts.java,ktexperts.class,ktexperts.php
In this 4 files I am going to ignore .class file while commiting.

To ignore the file while commiting


Create a new file “.gitignore” and keep content like pattern matching “*.class”

To see the .gitignore file and see the status of git

Adding to Staging Area 

[root@ip-172-31-42-20 mumbaigit]# git add .

Commit the file into Local Repository


Now onwards,if you create any file with extension of .class git will ignore those files automatically.

Create 4 new files

By using touch command.

We create 4 new files “ktexperts.txt,ktexperts.java,ktexperts.class,ktexperts.php”

To see the status of git

It is not showing ktexperts.class files because git has ignored that file.
If run add these 3 files only will add to staging area expect ktexperts.class.

Adding to Staging Area

Commit the file into Local Repository


Create one more file “DevOps.class”

To see the status git
We can see nothing to commit means git has ignored DevOps.class file.

Ignoring files manually while commiting

Make new files

Create new files “file1.java file2.java file3.java file1.txt file2.txt file3.txt file1.php file2.php file3.php”

To see the status of git

Adding files to Staging Area

Here,we add files to staging area(want to add) and ignore (don’t want to add).

Mention required file names.

we shouldn’t mention the file names which is you don’t want to add.

If you don’t specify file so that file won’t be added to staging area.

We can add files to staging area by using “*”
[root@ip-172-31-42-20 mumbaigit]# git add  *.txt *.java *.php

Commit into Local Repository


Git log Options
To see the list of all commits

To see the latest commit

To see the latest 2 commits

To see the latest 3 commits

We can give any number instead of 1 or 2 or 3
Based on the number it will display the list of commits.

To see all the list of commits in a summarized manner

It will show only first 7 characters of commit ID and commit messages.

Pick the commit by using grep
It will show the commits which belongs to commit message “london”

Thank you for giving your valuable time to read the above information. Please click here to subscribe for further updates

KTEXPERTS is always active on below social media platforms.


Facebook : https://www.facebook.com/ktexperts/
LinkedIn   : https://www.linkedin.com/company/ktexperts/
Twitter     : https://twitter.com/ktexpertsadmin
YouTube : https://www.youtube.com/c/ktexperts
Instagram : https://www.instagram.com/knowledgesharingplatform


Follow Me
Ramesh’s Linkedin : https://www.linkedin.com/in/ramesh-atchala/

Share via:
Note: Please test scripts in Non Prod before trying in Production.
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)

2 thoughts on “What is GItIgnore in Git?

  1. By seeing this article I came to get knowledge on GitIgnore in DevOps.
    Thanks for making and It has great information.

Add Comment