Up and Running with Git Transcripts
Chapter: Our first git repository
Lecture: Ignoring files in git and editors

Login or purchase this course to watch this video and the rest of the course contents.
0:00 So our app is amazing. It seems like it's working great. But notice that when we were here we have these seven files that are to do
0:12 with github that we could commit over in visual studio code. It also says there's a bunch of stuff going on here that could be committed.
0:20 And even when we do a commit here, there's a unversion files that is untracked the idea files. We probably, let's imagine, let's just decide.
0:30 We don't want to commit those at all and we want to get to stop complaining to us that here are a bunch of files that need to be changed when I
0:39 look in source tree, I don't want to see a seven. I want to see this project is fully committed and saved with these extra files.
0:46 We won't get that so we can in different places. Notice there's we go back here,
0:52 there's this git ignore file. Now the git ignore file has all sorts of stuff in it. And you're like, what is going on here? But notice,
1:00 first of all that we have this virtual environment, this 'venv' These are dedicated to different operating systems.
1:07 Different versions of Python, all sorts of stuff that should never be checked in. So we have these statements here,
1:14 let's say git please ignore any directory named venv or .venv or any variant there that they've come up with and that's why it's got this grayed
1:26 out or golden out sort of background color and this gold color that says this is not this is explicitly ignored by GIT.
1:37 So let's let's go down here and we could you can type in here so I could type in here that I don't want to get the idea folder files similarly over
1:47 in visual studio. I could do these as well. I could go and open up to git ignore or the way I actually usually like
1:55 to do this is with source tree because it gives you a little bit of help on the variations. Like for example,
2:01 one of the things I could do is I could say let's go over here and I want to right click. You have all these options.
2:07 Remember when I said that source tree is a UI that does not hide all the features of get. It just brings them along in a UI style sometimes that's even
2:16 too intense. This is a little bit of a view into that world, but it is, it does give you all the options.
2:22 So let's say we want to ignore this file in the repository. Now. I could just say,
2:27 okay, and that would pick this file will never show up as an option to be added to git or I could say I just want all the
2:35 iml Files anywhere in the project. I could put some custom pattern up here but what I want to do probably is
2:41 just say everything under the .idea folder. Please ignore that whatever it is and notice we get the choice of added to this
2:49 repository that will put it into our local git ignored, which has a huge benefit or I could ignore it globally.
2:55 So I just never have to think about this again. What's the benefit of this repository?
3:00 Only? I'll show you if I do this now we have no other pending files from that folder but now we have another change.
3:07 .gitignored has been changed with that addition there at the end to add. .idea. The benefit of this is when I check this into github and
3:16 other people get it. If they're also working with PyCharm, it will ignore those files for them as well.
3:23 So no one else working with this project might accidentally commit PyCharm. Project files either so that I think is a massive benefit.
3:33 So let's go in down here, go down here and say ignore PyCharm. Project files and if I wanted to do a commit and sync it already,
3:44 I could push this which will take the other changes we have as well. These other two there but that's not what I want.
3:50 I want to just commit this one not noticed. See that seven up there right here,
3:53 commit zero they're gone because now it knows there's these changes to the ignore files so all the files that were there,
4:02 they should be ignored so they disappear from what should be committed, syncing that back over to visual studio code.
4:07 You can see now the .idea folder is not lit up as something to commit Similarly, over here, when we go and commit in PyCharm,
4:15 there are now no changes to commit because the only files that are there either committed or ignored.

Talk Python's Mastodon Michael Kennedy's Mastodon