4 min episode 9 of 24
In this video, we’ll talk about how to ignore files.
In every project, there’ll be a couple of files that you don’t want to be version controlled: Mac OS, for example, creates those internal “.DS_Store” system files - which should not be included in version control.
In other projects, you might have cache or build files, logs, compiled sources and much more that makes no sense in your version control system.
You need to tell Git which files to exclude - by listing them in a simple text file. Let’s look at few common cases.
To ignore one specific file, simply note the full path to the file. File paths in this context are always specified from the root folder of your project. You can also ignore all files with a certain name - anywhere in the project. Just write down the file’s name, without a specific path.
To ignore all files of a certain type, note an asterisk and the file extension. Finally, to ignore all files in a certain folder, write down the path to that folder, followed by an asterisk.
Let’s try this in practice on a brand new project.
First, let’s create a new Git repository for this project in Tower. In the “Repositories” view, I click “Create” and select the root folder of my new project.
When I open this project, I see those pesky “.DS_Store” files (since I’m a Mac user). They don’t really belong to my project - and therefore, I don’t want to have them in version control.
Right-click the file and open the “Ignore” submenu. The plain “Ignore” item will just exclude this instance of the file. However, we want to exclude all its occurences, even in other places in the project. Therefore, I select “Ignore all items like this”.
Notice that Tower now lists a “.gitignore” file. This is where those ignore rules - the file patterns you want to exclude - are kept. It’s just a simple plain text file in the root folder of the project. You could inspect and modify it in any text editor.
One thing is very important here: ignoring only works for that are not under version control. You cannot ignore a tracked file. So, it makes lots of sense to craft your ignore rules right at the beginning of your project. Before committing all those unwanted files.
By default, Tower doesn’t show ignored files in your working copy. If you should ever want to see them in your file structure, you can tell Tower to show them anyway.
Note that the gitignore file is version controlled like any other file in your project. This also means that its contents are shared and valid for all team members.
If you should ever want to exclude a file only on your machine - without affecting your teammates - there’s something for you. You can create a so-called “exclude file” that is only valid for you.
It’s placed inside of your local Git repository. It’s not version controlled and therefore not visible for other people in your team.
In most cases, the global gitignore file is just what you want. However, if - for example - you’re the only Mac user in a 10-person Windows team, ignoring DS_Store files only locally in your exclude file is a valid option.
That’s it for now. Thanks for watching - and see you soon in our next videos!