DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Terraform Drift Detection at Scale: How to Catch Configuration Drift Early
  • Git Tags vs AWS Tags: A Tag-Tastic Showdown!
  • GitOps Software Development Principles – And the Benefits for the Entire Organization
  • Why GitOps Is Gaining Popularity in DevOps: A Deep Dive Into the Future of Infrastructure Management

Trending

  • The Modern Data Stack Is Overrated — Here’s What Works
  • Infrastructure as Code (IaC) Beyond the Basics
  • Enhancing Security With ZTNA in Hybrid and Multi-Cloud Deployments
  • Understanding and Mitigating IP Spoofing Attacks
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. DIG in Your GIT — Best Practices

DIG in Your GIT — Best Practices

In this article, explore .gitignore and see the different types and the basic rules.

By 
Rajeev Bera user avatar
Rajeev Bera
DZone Core CORE ·
Aug. 14, 20 · Opinion
Likes (4)
Comment
Save
Tweet
Share
14.7K Views

Join the DZone community and get the full member experience.

Join For Free

This is one of the easiest best practices, which you can start using in less than 2 minutes. But the impact will be huge.

Today I will share one of my all-time favorite practice - DIG in your GIT

And I have a bonus section for you, I am sharing two downloadable pdf with 51+ important git commands with a one-line summary and 35+ git best practices with you in this post. 

Don’t Ignore .gitignore (DIG) in your Git repository. I have noticed in the past many developers do not use a .gitignore file.

Use the .gitignore file is one of the git best practices. And I will cover in this post how gitignore can boost your code quality with other advantages.

Also, I will explain how you can use your global .gitignore file (without adding or pushing). And this comprehensive file will be used by all your repository.  

So let’s dive in…

What Is .gitignore?

There is not any git ignore command which you can use directly to ignore the unwanted files in your repository; instead, you should use .gitignore file.

In simple words, the .gitignore file is a text file that tells Git about which files to ignore.

Git checks three things in your working copy. 

  1. Untracked — Your changes that have not been staged or committed.

  2. Tracked — Your all changes that have been previously staged or committed.

  3. Ignored — All files which you told to Git to ignore.

It's easy to create .gitignore file, create a text file, and name it .gitignore (that’s it)

Remember to add a single dot . at the beginning of this file name.

How Many Types of .gitignore Files? 

I have seen many developers use the local .gitignore file. They add the gitignore file in their project repository. But very few use the global file. In this section, I will explain both.

There are two types of .gitignore files.

  1. Local .gitignore file

  2. Global .gitignore file

Local .gitignore

If you add the.gitignore file in the root of your git repository, it will be considered as a local file. It means that the .gitignore file will work on that repository.  And .gitignore file should be committed to your repository.

Global .gitignore File

If you place a similar file in the root of your home directory, it will act as a global .gitignore file.

What is means?

This file affects every repository you use on your machine. 

The most significant advantage of using a global file is that you don’t need to commit it. And making one change affects all of your repositories. 

Basic Rules for .gitignore File

Each line in the .gitignore file specifies a pattern.  Here are some basic rules that help you to set up the .gitignore file

  1. Any line in the .gitignore file starts with a hash (#) is a comment.
  2. \ character is used to escape special characters
  3. / figure indicates that the rule applies only to files and folders, which are located in the same folder
  4. An asterisk (*) means any number of characters (zero or more occurrence)
  5. Two asterisks (**) are used to specify any number of subdirectories
  6. A question mark (?) replaces zero or one character.
  7. An exclamation sign (!) indicates the inversion rules.
  8. Blank lines are ignore
  9. You can ignore entire directories paths and adding a / on end:

What Files Should Be Ignored

You can ignore many files which are usually auto-generated, platform-specific, and other local configuration files. 

  1. Files with sensitive information 
  2. Compiled code, such as .dll or .class
  3. System files like .DS_Store or Thumbs.db
  4. Files with temporary information like a log, cache, etc.. 
  5. Generated files like dist folders

Advantages of Using gitignore

Here the top 3 advantages (that’s why I use .gitignore)

  1. It helps you to clean your code repository by ignoring unwanted files.
  2. Your repository size stays under control, especially if you are working on a big project.
  3. Your every single commit, push, and pull request will be clean. 

There is no doubt that Git is powerful. But in the end, it's just another computer program.

So it's a team effort to use best practices and to keep your code repo stable and make sure you use git ignore file. 

Also, you can download the 51 git commands and 35 Git best practices from here

So let me know, do you prefer local gitignore or global gitignore file?

Git Dig (command)

Opinions expressed by DZone contributors are their own.

Related

  • Terraform Drift Detection at Scale: How to Catch Configuration Drift Early
  • Git Tags vs AWS Tags: A Tag-Tastic Showdown!
  • GitOps Software Development Principles – And the Benefits for the Entire Organization
  • Why GitOps Is Gaining Popularity in DevOps: A Deep Dive Into the Future of Infrastructure Management

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!