Join us and get access to thousands of tutorials and a community of expert Pythonistas.
This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.
Ignoring Irrelevant Files
00:00
In the previous lessons, you saw that Git constantly reminds you that __pycache__ is a folder that’s not being tracked. And not only is that visual noise, because not only do you know that __pycache__ is there, but you also know you don’t care about it, but it also prevents you from using useful shortcuts like git add ..
00:18
So what you can do to fix this is create and open a file called .gitignore altogether. And now in this file, you’re going to list one per line, you’re going to list all of the files and folders that you do not want Git to track, or in other words, that you want Git to ignore.
00:39
So you’re going to start by typing __pycache__. And now if you save that file, and you go back to your terminal, try running git status.
00:50
Notice how __pycache__ is no longer in the output, even though __pycache__ is not being tracked, but Git is just ignoring it. And now you have the file .gitignore.
00:59
Ironically, you will want to add and commit the file .gitignore, but every single other file and folder that’s listed in .gitignore doesn’t even show up in your git status output.
01:11
So go ahead, run git add .gitignore, and then git commit. And then you can type something like “Ignore pycache folder.” for your commit message.
01:25
And there you go. If you run git log, you will now see a new commit where you add the file .gitignore. Once you’re done ignoring the __pycache__ folder and committing the .gitignore file, move on to the next lesson where you’re going to recap everything you learned so far.
Become a Member to join the conversation.