Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Git Tutorial 25 – Important Pattern Formats For the .gitignore file

Posted on 02/08/2025 By admin

As a part of GIT Tutorials End To End, we will learn about the important pattern formats for the .gitignore file in this post.

I will expect that you are aware of the basic concepts and commands of GIT. But if you are a beginner in GIT then I strongly recommend you to refer GIT Basic Commands and Concepts section on my blog first.

If you are now aware of the .gitignore file or how to create it then you must go through this post – Ignore Files Using the .gitignore

Did you know that I have started a YouTube channel as well and I need your support to make it successful. Please do watch content then comment, like, share, and obviously subscribe.

First of all, we can have multiple .gitignore files in different directories of the same project. Every pattern specified in the .gitignore file will be relative to the location of .gitignore file.

Let’s create a local git repository with .gitignore to practice –

To ignore a specific file you just need to mention the file name in the .gitignore file. I created a file named fileA.txt and the git status command output shows fileA.txt as an untracked file.

Let’s add fileA.txt in the .gitignore file. You can see that fileA.txt is now an ignored file i.e. git will not show it as an untracked file. In fact, git will not bother at all about the file fileA.txt.

Here is an important point. All files with the name fileA.txt will be ignored in the directory. I will create a subdirectory and then create a new file fileA.txt. In this case, both the fileA.txt will be ignored as well. Please note that you need to pass the file name with the extension otherwise git will look for files and directories with the given name.

If you want to ignore a specific file present in a directory then you need to pass the file name with a relative path. To ignore fileA.txt present in the root directory, pass it in the .gitignore file as “/fileA.txt“. To ignore fileA.txt present in the myDir, pass it in the .gitignore file as “myDir/fileA.txt” or “/myDir/fileA.txt“.

Please note that names are case insensitive i.e. FileA.txt and filea.txt are the same for the .gitignore file.

If you want to ignore files with a specific extension then you can use an asterisk i.e. “*.html“. It will ignore all files ending with .html without bothering about their names.

If you have a requirement to ignore all but with an exception then you can use negating pattern using an exclamation mark i.e. “!abc.html”.

With both patterns in the .gitignore file, all .html files will be ignored but abc.html will not be ignored.

Please note that an asterisk can be used if you want to ignore a file with a specific name ignoring its extensions. A pattern “dummy.*” will ignore all files whose name is “dummy” ignoring their extensions.

If you want to ignore files whose name contains or starts or ends with a specific word then also you can use an asterisk.

“demo*” -> It will ignore all files and directories whose name starts with “demo”.

“*demo” -> It will ignore all files and directories whose name ends with “demo”.

“*demo*” -> It will ignore all files and directories whose name contains “demo”.

The wildcard character asterisk represents more than one character. To represent only one character we can use the question mark. A pattern as “Dummy?.html” will ignore Dummyy.html but not Dummyyy.html.

We can also add patterns to ignore directories in the .gitignore. If you want to ignore all files inside a directory including subdirectories then just use “/” i.e. “testResults/“. All contents of folder testResults will be ignored by git. Please note here that appending slash with directory name represents that git needs to ignore directory with the given name, not files. If we use a pattern without a slash then git will ignore files and directories with the given name.

There are many other patterns as well which you can refer to in the official documentation here. ABove examples will help you to understand the basics and most used patterns.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe to my YouTube channel.
#ThanksForReading
#HappyLearning

Uncategorized

Post navigation

Previous Post: Advanced Xpath Concept – Method normalize-space & Its Usage
Next Post: Java Interview Question – Explain public static void main(String[] args)

Related Posts

PROTRACTOR TUTORIAL 2– Identify Angular and Non-angular Application Uncategorized
xpath in chrome – Make Selenium Easy Uncategorized
January 21, 2018 – Make Selenium Easy Uncategorized
findElement() And findElements() Methods in Selenium WebDriver Uncategorized
Create a Map From Excel Data in Java – Selenium – API Automation Uncategorized
March 18, 2018 – Make Selenium Easy Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark