How to Create a .gitignore File: Step-by-Step Guide

When working with Git, there are often files you don’t want to track—like logs, environment settings, or other temporary files.

This is where the ‘.gitignore’ file comes in handy.

In this step-by-step guide, let’s check out how to create a ‘.gitignore’ file for your project, so you can keep your repository clean and avoid sharing unnecessary files.

How to Create a .gitignore File

Follow the below-mentioned steps to create and add a '.gitignore' file to your project, helping you manage which files to keep out of your Git repository.

Steps to follow:

1. Click on the 'Add New File' icon in your root directory.

2. Name the file as '.gitignore'.

3. Add the name of the file or folder that you want Git to ignore.

4. Add a '/' at the beginning to ignore files or folders only in the root directory; otherwise, all files or folders with that name will be ignored.

5. Add a '/' at the end to ignore only folders; otherwise, both files and folders will be ignored.

6. Click the 'Source Control' icon in the left sidebar.

7. Click on 'Stage Changes' icon to stage your changes.

8. Enter your commit message.

9. Click on 'Commit' to commit your changes.

That's it!

You have now successfully added the .gitignore file to your project.

Conclusion

Creating a ‘.gitignore’ file is one of those small but essential steps that make working with Git much smoother.

Now that you know how to set it up, you can ensure that your project only includes the files that truly matter, keeping your repository organized and easy to manage.

Remember, it’s all about making collaboration smoother for you and your team!

Still have questions?

Send an email to archana@leadwalnut.com, OR

Book a FREE consultation with an expert developer here.