Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Git Tutorial 24 – Ignore Files Using .gitignore

Posted on 02/19/2025 By admin

As a part of GIT Tutorials End To End, we will learn about the .gitignore file or ignoring file and directory in git 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.

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.

When we create a new file in a git repository, it is marked as Untracked by Git. Git will ask you to stage/commit untracked files. But all the files created or autogenerated are not meant to push to the remote repository. For example – a folder named target is auto-created locally by a maven project during the build. This target folder is not required to commit and push to remote. In short, some files and folders need to be marked ignored for git. An ignored file by git will not be tracked for any action on the file.

By default, git will not ignore any file. We need to intentionally let git know about files and directories to be ignored.

In fact, there is no command to ignore a file in Git. You must need to mention the file or directory name to be ignored in the .gitignore file. A .gitignore file is generally kept in the root directory and must be committed and pushed to the remote repository. Let’s see these concepts in action.

I just initialized a git repository and created a file FileA. Git marks FileA as untracked.

I want FileA should not be tracked by git. For this to happen I need to create a .gitignore file and add FileA in the .gitignore file. The best way to create a .gitignore file is using the touch command shown below.

Please note when I added FileA in the .gitignore file then git is no longer saying that FileA is untracked like the previous screenshot. FileA is ignored by git now. Anyway .gitignore is shown as untracked which we should commit and push to remote.

Please note that a file whose name starts with period (.) is hidden from normal view. In git bash, you need to run ls -a command to see it. You also need to do some changes based on the operating system to see these files in the file directory.

If you want to add more files to .gitignore file then either you can use Linux commands or the file directory to edit it. Let me create a new file inside a folder and add it to .gitignore file.

Please note the pattern I used above. Since I have kept the file in demoFolder, so I need to pass it as “demoFolder/FileB”. There are multiple patterns to add in the .gitignore file. We will see some important ones in the next post.

  1. We can create a .gitignore file using the touch command which works on all OS.
  2. Files and directories mentioned in the .gitignore file will be ignored by GIT.
  3. There are multiple patterns to use to mention entries in the .gitignore file.
  4. We should place the .gitignore file in the root directory and commit and push it to remote.
  5. We can have more than one .gitignore file in a repo. It is helpful in multimodule projects.

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: Git Tutorial 20 – Untracked File Vs Unstaged File
Next Post: Postman Tutorial Part 22 – Postman Console – Debugging And Logging

Related Posts

REST Assured Tutorial 25 – How To Create a JSON Object Using Jackson API – ObjectMapper – createObjectNode() Uncategorized
August 20, 2017 – Make Selenium Easy Uncategorized
May 31, 2017 – Make Selenium Easy Uncategorized
TestNG Tutorials – Page 5 – Make Selenium Easy Uncategorized
December 16, 2017 – Make Selenium Easy Uncategorized
October 4, 2017 – 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