Create Automated .gitignore Files for Your Project

Akash Gutha
InstructorAkash Gutha
Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 5 years ago

This lesson explores what git ignore files are and automating the creation of git ignore files.

The methods covered in this lesson for creating git ignore files are :

  1. Manual Method
  2. Using Github Site
  3. using an IDE
  4. using Gitignore.io

Let's initialize a Git repository here. You can see that I have a TypeScript project set up over here. In the package.json, I've added TypeScript types dependency.

If we check our Git status, you can see that node modules is being tracked by our Git repository, which is not what we desire. Gitignore files solve this exact problem by letting us ignore the exact files and folders that we desire not to be included in our git repository.

Let's add a gitignore file. If you head to the Git tab, you can see a bunch of files that are being tracked from the node modules folder. If we add node modules into our gitignore file, and wait for the changes to reflect, you can see that all the files and folders from the node modules folders are now not being tracked by the tracking system.

Creating gitignore files is daunting, and basically, it should always be automated. I'll show you a couple of ways you can do this.

If you go to your GitHub account and make a new repository, let's name this test. If you come down, you can see a add.gitignore button. If you press this, it will give you a list of options to choose from. Let's say, "Add project as a node project."

I'll type in node, and you can see that we have a node option here. Select it and create a repository. Once a repository is created, you have .gitignore file over here. If you open it up, all the files and folders set up for you. You can copy it and paste it in your project.

This is a bit lengthier process. The shorter way is to use tools provided by the ID. Let's head back to Visual Studio code. Let's go to the extensions, and search for gitignore. You can see that we have an extension that does this. It's called as the gitignore extension.

I already have it installed. You can go ahead and install it. If you open up the command panel and search for the command add gitignore, you'll be given a list of options from which you can choose.

I'll again type in node to add a node.gitignore. It will ask me to append or overwrite. I'll append it to our existing gitignore file. If we go ahead and open our gitignore file, you can see that new files and folders have been added to gitignore.

Though all of these ways are good, the most recommended way is to use gitignore.io. Suppose you're making a node project with angular, and you're using Visual Studio as an ID. I'll write in node, and then angular, and for the ID, I'll write in Visual Studio.

As I press create, it will generate me the gitignore file that I can simply copy and paste into my project.

egghead
egghead
~ 41 seconds ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today