Mastering PyCharm Transcripts
Chapter: Source control
Lecture: Accessing source control

Login or purchase this course to watch this video and the rest of the course contents.
0:03 To start our exploration of source code and its integration with PyCharm,
0:06 let's just look at our github repository here, mastering pycharm course,
0:10 we've already talked about where this lives,
0:12 but you'll notice that there's really nothing going on here
0:15 like a little while ago, I put the course image and I've updated the read me apparently
0:19 but nothing has been committed
0:22 and also notice that there are two branches
0:24 like imagine, this is just to sort of pretend,
0:26 I'm doing some sort of feature branch thing
0:28 so I've got this feature branch one
0:31 and maybe I'll issue a pull request back to the main master branch.
0:36 What we want to do is we are going to go back to the code that we already wrote
0:40 and when I first did that, we did the editor stuff and the project stuff
0:44 what I did is I created a folder called "demos" in here
0:47 but I didn't check it in or anything, because we hadn't gotten to the source control part yet.
0:52 So here we are in one of those programs
0:54 remember we got one, we can go and download from the podcast
0:57 so I could run this and it will tell us what the items are
1:01 basically available on Talk Python right now.
1:04 So you can see that we're getting,
1:08 I guess we are getting the 0 to
1:14 129th one down here, we're not getting all of them.
1:17 Here in program, we're only showing this little bit.
1:19 You can see this is working fine, but it has not been checked into source control
1:23 so how do we go about this?
1:25 I created this folder inside, let's go to my desktop,
1:29 I created this folder here inside the course,
1:33 here you can see the read me, and all those kinds of things.
1:35 We go over there, let's say go to the desktop course,
1:39 this is a git repo, and we have some files in here,
1:43 some that are new, some that are modified okay,
1:48 so let's go check that out.
1:50 Now, if I just open this project,
1:52 automatically it knows it's part of git, so go to the menu first
1:55 up here notice there's a bunch of non grayed out
1:58 commit, update source control options
2:02 and we could go and say check out from github
2:06 or some other types of things,
2:08 but because we've already opened it
2:11 there's actually a lot of git features available to us.
2:13 So we could commit a file, we could add it,
2:16 we can merge changes, we could reset it to the latest, all of these sorts of things.
2:20 I could even create a pull request, how cool is that.
2:23 So a lot of stuff can happen up here
2:25 notice there is also a local history which is amazing
2:27 we'll talk about that in a minute.
2:29 For now, we're going to focus on the real,
2:31 grown up git source control stuff.
2:34 So, this is all great, you might use that,
2:37 but typically I find myself here extremely rarely.
2:40 So let's look down here,
2:43 notice this, it says git master, how awesome is that?
2:47 Because we're in a repository it automatically knows,
2:49 actually the very first time we opened it, it noticed it was a git repository
2:53 and it asked should I add integration for it and I said yes,
2:56 so that's technically the yes it's required,
2:59 but down here now if I click on it, I get branch information.
3:01 Notice I could tag a branch, create a new branch, I'm on master local
3:05 and on remote, I have my feature branch
3:09 so I could do things like check it out,
3:11 because it doesn't exist in local and things like this
3:14 so we'll come back to the branching,
3:16 but notice right away it tells us sort of where we're working
3:19 and then up here, these are all the run options
3:21 but on the right, we have update project, commit the changes,
3:26 this shows the history, not committed, so there's no history, we'll revert it back.
3:31 So this little group of four things is also your source control.
3:35 And finally, it might not be obvious yet,
3:37 let's go ahead and mark this as excluded so we don't look at it,
3:41 the green here actually means this is a new file
3:46 so if I go back over here, it is this little bit right here.
3:53 The green means new file here,
3:55 if it were modified it would actually be blue not red,
3:58 and if it were not tracked it would be basically that color.
4:02 So if I go over here and I add another file
4:04 let's just call this other.txt,
4:07 I told PyCharm when I created this project
4:11 that it was allowed to automatically add things to source control,
4:14 but if I added it without, it would show up as red.
4:17 So now let's go ahead and commit these,
4:20 probably the first thing we want to do is get the latest changes.
4:24 So we can go over here and say get me the changes
4:26 and we'll just pull those down,
4:29 it says okay, everything's up to date, great.
4:31 Now let's go ahead and check them in,
4:33 so let's go commit, so we'll come down here and it says
4:36 these are all the files that we're actually going to commit for you
4:39 there's some project files that's going to track for us
4:43 but these are the ones that we're looking at
4:45 and then there's a bunch of unversioned files that it's not tracking
4:47 some project files that we could ignore we'll come back to that later.
4:51 Okay, so what we want to do is we want to check those in,
4:55 we'll give it a message, whatever it is you do when you do your check in
4:59 so this is committing the early work.
5:04 We could come over here and reformat the code
5:07 according to our rules before we check it in,
5:10 we could do certain things like optimize the imports,
5:13 perform code analysis, other types of clean up.
5:17 So there's all sorts of stuff, we could even push it to production if you would like,
5:20 I am not a fan of that but you can.
5:23 So down here you can see your differences,
5:26 this is all green because it's all new, not a lot going on.
5:28 Now remember git is two staged,
5:30 so if I just click commit, it's just going to stage it locally,
5:33 what I really need to do is commit and then push those changes up,
5:37 so I'll do that all in one shot.
5:40 And it comes back, it says
5:42 okay you need to push this stuff, you are going to push it here,
5:45 we could push tags and things like that, but let's just go.
5:47 Wait a second— ta-da, it was updated.
5:52 Now if we go back to github and we refresh,
5:55 There it is, committing the early work, 17 seconds ago.
6:00 So we come down here, we were on this one, the podcast.
6:04 So, down here we're got the work that we did, awesome.
6:08 Let's go over here and make some changes,
6:10 because we're not quite done exploring this yet.
6:13 So I told you if we made some changes that the color would change again,
6:17 so let's go and suppose in program, what we want to do
6:21 is we actually want to get 120 to 141,
6:25 so we made some changes here, and if I go over there,
6:30 notice it's already turned blue, that means it's been changed,
6:33 it was in source control, it's been changed.
6:35 I can come over here and I can save, and we could say
6:38 show me the history now,
6:41 now we have some history, right, this was checked in,
6:43 so we have our local changes, our log of what has been changed,
6:47 our console down here for our git action,
6:50 and then this, we could actually show the diff on
6:54 that is not super interesting yet, is it;
6:58 because we just checked it in.
7:02 Alright, so last thing, let's do it from here, actually this one from here,
7:08 so we could compare with the current version,
7:11 now we can see that we've changed this one line, right,
7:16 so this is standard git changes.
7:19 Okay, so pretty awesome, let's just go and push our final change up,
7:22 later episodes, something like that, and we'll do a commit and push,
7:28 and push, awesome, I'll commit it.
7:36 Finally, let's look at annotations,
7:40 so if I click on annotate, it will come along an it will say
7:44 who has made these changes, when the changes were made,
7:47 you can click here and it will actually show you that check in, right,
7:51 if I click on this one, it will say look
7:53 we just checked in that one file with this change,
7:56 if I click here— now it's not super interesting
7:59 because there is only 2 versions and it was all me,
8:01 but you can imagine in a real application in a real project over time,
8:04 this annotate is super cool.