Getting Started with Git

Aug 14 2023 · git 2.28, console

Part 1: Getting Started with Git

10. Ignoring Files

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 09. Using the Command Line Next episode: 11. Conclusion

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Transcript: 10. Ignoring Files

Often in projects, there would be files that you don’t want to include in your project. For example, in an iOS project using Cocoapods, maybe you don’t want to include the actual Pods in your project and have developers just get them locally. Or maybe you have a static site generation tool that converts markdown to html for you, and you only need to check in the markdown files. You don’t actually need html files in your project. Let’s pretend that’s our use case and we want to avoid checking in any html files to our project by leveraging gitignore.

Let’s add a few html files to our project. Open up your text editor and add a “a.html” file and a “b.html” file in the root of your project. Then create another folder called “site”, and add a “c.html” file.

Go to the GitHub desktop app. Git recognizes the changes and thinks we want to commit them.

Now create a “.gitignore” file at the root of your project. Add *.html. This tells Git to ignore files that match this pattern. Match all files that have an .html extension and ignore them.

Return to the GitHub app and notice how Git ignores all .html files. Great!

Now let’s pretend that you want the html files at the root of your directory, but not the ones in the site folder.

Go back to your gitignore file and add site slash in front of the star dot html. This will now match html files in the site folder only.

It won’t match html files in the root of the project.

Go back to the GitHub desktop app and notice how the a and b html files that are in the root of the project are seen as changes to Git once again, but the c.html file in the site folder is not.

Commit this gitignore file with the message, “Added gitignore ignoring html files in site directory.”

There are more things you can do with gitignore depending on your needs on what files to match and not match, but they are beyond the scope of this course. But you now know why we use gitignore and the basics on how to use it.