Visual Studio Code for Python Developers Transcripts
Chapter: Source Control with Git
Lecture: Working with a Git Repository
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
So now that we know a little bit about the role of source control and some of the things that we might want to do with it,
0:07
why don't we see what it actually looks like to start working with Git and source control inside of VS Code?
0:13
Now, for folks that maybe you're already used to working with source control
0:18
via the command line, again, regardless of whether you're using Git or Mercurial or SVN or any of those other tools,
0:24
you can still have that same workflow inside of Visual Studio Code. And the only thing that you need to do is just pull up the built-in terminal
0:32
and you can start executing commands just like you would have in your regular workflow. Now, while this is a great experience,
0:40
and I think it's good to allow folks to easily migrate over to using new tools, VS Code, the wonderful editor that it is,
0:48
has tons of different options built in that you could use either by accessing a menu or using the command palette.
0:54
So, Brian, why don't you show us some of the things that are inside of the command palette just specifically for working with Git?
1:00
Sure. And really quick, I just want to remind folks that we talked about shortcuts in VS Code earlier, in an earlier chapter.
1:06
To bring up the terminal, the built-in terminal, if you want, you can press control or command back tick to toggle that on or off.
1:12
And that way you can start doing your things that you're used to doing with the command line directly in Visual Studio Code,
1:18
like Git status and all the different Git commands you might use there. But for now, let's hide that.
1:23
And let's talk about the command palette, like Cecil said. So I bring that up with control shift P on Windows and Linux. Command shift P on macOS.
1:30
And if I start typing in Git, now I can see all the available commands that are provided to me through the command palette from Visual Studio Code.
1:39
So I can clone a repo, I can add remotes, I can apply stashes, I can commit files and changes that are going on, and so forth.
1:49
And that's one way to go about doing this. And that's one of the main ways that you can do it with where
1:53
it allows you to keep your hands on the keyboard, one of the ways I prefer personally. Or if you're more of a pointy-toe,
1:58
point and click type of person more visually, all those actions that we were just talking about, if you bring up the source control view,
2:04
which keyboard shortcut for that, we're going to call that out again, control shift G, G, and bring that up. Or you just click on that icon there.
2:12
And then these three little dots, more actions menu, all those things we were talking about that you might want to do
2:18
that's within the space of source control management using Git is available to you through this menu.
2:23
Now, one of the things I really love about using the menu is well, one, I don't know every Git command. So if I wanted to kind of see what one,
2:33
what are some of the operations I could do, or what are some of the different options within those different commands,
2:40
I could easily use the menu and click through. And now I could still be very productive, but also continue to learn about the capabilities that
2:47
my source control provider has. Yeah, it's a great way to learn. In fact, I'm seeing ones right now that I've never used before
2:55
or heard of before that I'm learning about too. And the different types of commands that I'm learning about too. I'm learning about the types of like,
2:59
normally I just do a Git pull, but apparently there's a Git pull rebase or Git pull from type of command that is available or just syncing in general.
3:06
Those types of things I don't typically use in the past, like from the command line. So it's interesting to see that populated in Visual Studio Code
3:14
to make that more aware to me, and I can learn something new about that. Take a quick second and actually go through some of those commands
3:22
that we may have used before, maybe we've never seen before. Sure. I think for me, one of the most common options
3:28
to kind of mess around with is using branches. And so for folks that don't know what branching is,
3:35
let's say you're working on a project and you have like a main, your main timeline that is your project,
3:43
but maybe you want to add a feature or you want to kind of experiment with something, but you don't want to mess up your main workspace.
3:50
Well, essentially you can kind of create somewhat of a copy. It's kind of like taking a fork in the road, right? Like I'm going to make a left turn.
3:57
The other road is still there. But I'm just making a little bit of a deviation to kind of explore and see what can happen there.
4:02
And then at some point I could either forget about that fork, forget about that copy, or I can bring them back together.
4:08
So one of the good things you can do is navigate through some different branches.
4:12
So why don't we go ahead and see, like, how can we do that inside of VS Code? Sure.
4:17
Well, one of the ways I'm going to go about doing that is bringing up the command palette again, and I'm going to say git branch.
4:22
And what we can do now is from my current branch, which is the main branch, and the way I can double check that is,
4:28
one, it's kind of hiding behind you, Cecil, right now, but in the status bar it shows you down there that it's the main branch.
4:34
But if I click on it, you can see it gives me the option to create a new branch, create a new branch from this one,
4:40
but also showing me my local main instance of the branch, and then the remote branch, which is over at my origin, which is in this case up on GitHub.
4:48
So if I wanted to create a new branch from this main branch, which means taking the current state of it and moving it into whatever is there,
4:55
assets, code changes, whatnot, copy, copying it over into a new branch, basically.
5:00
So I'll say new branch from here, and we'll call it this demo branch. And now, while it's not necessarily a parent,
5:08
but I have a local instance of that branch that I'm working on within Visual Studio Code.
5:13
One of the things that we do when we're actually inside of a branch, regardless of whether it's our main branch or, you know,
5:19
a feature branch or a side branch, is we probably want to commit the code, right? And so when we talk about making commits,
5:25
this really means that, like, we've made some changes to some files, maybe we've added, removed, you know, moved some things around a little bit.
5:32
But what happens is, you know, the original state of our project and what it is now after our changes are different.
5:38
So what we want to do is make sure that we save these changes, and not save them in the sense that they're saved to the file system,
5:45
but we want to save them to the repository. So one of the things that we can do inside of Visual Studio Code
5:50
and how VS Code visualizes those changes, it says, is if you take a look at the activity bar on the right side, you'll notice, like,
5:58
the Git panel, right, has, like, some numbers next to it. And those numbers will show you exactly how many different files have changed.
6:07
And then if Brian clicks on that really quick, you'll see, well, we have one, two, three, four, we have about five files that have changed.
6:13
And if he simply clicks on one of those files, we should be able to see a diff, right?
6:18
So now we're seeing, well, what does the original one look like on the left side? What does the new version look like on the right side?
6:26
And now if we wanted to, the next thing that we're going to do is we're going to do a little bit of a change in the changes.
6:31
So what we're going to do is we're going to do a little bit of a change in the changes.
6:34
And what we're going to do is we're going to do a little bit of a change in the changes.
6:37
And what we're going to do is we're going to do a little bit of a change in the changes.
6:40
And what we're going to do is we're going to do a little bit of a change in the changes.
6:43
And what we're going to do is we're going to do a little bit of a change in the changes.
6:46
And what we're going to do is we're going to do a little bit of a change in the changes.
6:49
And what we're going to do is we're going to do a little bit of a change in the changes.
6:52
And what we're going to do is we're going to do a little bit of a change in the changes.
6:55
And what we're going to do is we're going to do a little bit of a change in the changes.
6:58
And what we're going to do is we're going to do a little bit of a change in the changes.
7:01
And what we're going to do is we're going to do a little bit of a change in the changes.
7:04
And what we're going to do is we're going to do a little bit of a change in the changes.
7:07
And what we're going to do is we're going to do a little bit of a change in the changes.
7:10
And what we're going to do is we're going to do a little bit of a change in the changes.
7:13
And what we're going to do is we're going to do a little bit of a change in the changes.
7:16
And what we're going to do is we're going to do a little bit of a change in the changes.
7:19
And what we're going to do is we're going to do a little bit of a change in the changes.
7:22
And what we're going to do is we're going to do a little bit of a change in the changes.
7:25
And what we're going to do is we're going to do a little bit of a change in the changes.
7:28
And what we're going to do is we're going to do a little bit of a change in the changes.
7:31
And what we're going to do is we're going to do a little bit of a change in the changes.
7:34
And what we're going to do is we're going to do a little bit of a change in the changes.
7:37
And what we're going to do is we're going to do a little bit of a change in the changes.
7:40
And what we're going to do is we're going to do a little bit of a change in the changes.
7:43
And what we're going to do is we're going to do a little bit of a change in the changes.
7:47
And what we're going to do is we're going to do a little bit of a change in the changes.
7:50
And what we're going to do is we're going to do a little bit of a change in the changes.
7:53
And what we're going to do is we're going to do a little bit of a change in the changes.
7:56
And what we're going to do is we're going to do a little bit of a change in the changes.
7:59
And what we're going to do is we're going to do a little bit of a change in the changes.
8:02
And what we're going to do is we're going to do a little bit of a change in the changes.
8:05
And what we're going to do is we're going to do a little bit of a change in the changes.
8:08
And what we're going to do is we're going to do a little bit of a change in the changes.
8:11
And what we're going to do is we're going to do a little bit of a change in the changes.
8:14
And what we're going to do is we're going to do a little bit of a change in the changes.
8:17
And what we're going to do is we're going to do a little bit of a change in the changes.
8:20
And what we're going to do is we're going to do a little bit of a change in the changes.
8:23
And what we're going to do is we're going to do a little bit of a change in the changes.
8:26
And what we're going to do is we're going to do a little bit of a change in the changes.
8:29
And what we're going to do is we're going to do a little bit of a change in the changes.
8:32
And what we're going to do is we're going to do a little bit of a change in the changes.
8:35
And what we're going to do is we're going to do a little bit of a change in the changes.
8:38
And what we're going to do is we're going to do a little bit of a change in the changes.
8:41
And what we're going to do is we're going to do a little bit of a change in the changes.
8:44
And what we're going to do is we're going to do a little bit of a change in the changes.
8:47
And what we're going to do is we're going to do a little bit of a change in the changes.
8:50
And what we're going to do is we're going to do a little bit of a change in the changes.
8:53
And what we're going to do is we're going to do a little bit of a change in the changes.
8:56
And what we're going to do is we're going to do a little bit of a change in the changes.
8:59
And what we're going to do is we're going to do a little bit of a change in the changes.
9:02
And what we're going to do is we're going to do a little bit of a change in the changes.
9:05
And what we're going to do is we're going to do a little bit of a change in the changes.
9:08
And what we're going to do is we're going to do a little bit of a change in the changes.
9:11
And what we're going to do is we're going to do a little bit of a change in the changes.
9:14
And what we're going to do is we're going to do a little bit of a change in the changes.
9:17
And what we're going to do is we're going to do a little bit of a change in the changes.
9:20
And what we're going to do is we're going to do a little bit of a change in the changes.
9:23
And what we're going to do is we're going to do a little bit of a change in the changes.
9:26
And what we're going to do is we're going to do a little bit of a change in the changes.
9:29
And what we're going to do is we're going to do a little bit of a change in the changes.
9:32
And what we're going to do is we're going to do a little bit of a change in the changes.
9:35
And what we're going to do is we're going to do a little bit of a change in the changes.
9:38
And what we're going to do is we're going to do a little bit of a change in the changes.
9:41
And what we're going to do is we're going to do a little bit of a change in the changes.
9:44
And I think that's a good segue and probably the last thing we're going to talk about in this particular video is remotes. So what exactly is remote?
9:52
Right now, kind of like what Brian was saying, he has, you know, the demo branch that's there.
9:57
There's also that main timeline that we talked about, like that main branch.
10:00
So there's almost like different, there's different train tracks of the same application that's there.
10:05
But one of the things that you could do is, hey, well, while all these changes are on my machine, I might want to share them with somebody.
10:13
And, you know, of course, I could put them on a thumb drive or just pick up my laptop and like, you know, drive to another city and try and share them.
10:21
But I can also use one of those services we mentioned in the previous video, like GitLab or GitHub. And I could use a remote repository.
10:29
Right. So pretty much just like a copy of the repository I have on my machine just hosted somewhere else.
10:34
I can use a remote repository and send my changes over there. We talk about working with remotes.
10:39
We're really talking about, like, how can I take my code from on my machine and share it with somebody else?
10:43
And then I can just take my code from my machine and share them to another space.
10:46
Again, that remote repository might be like a cluster inside of my house in case, you know, that's the thing that we want to do.
10:53
Or it could be, again, inside of GitHub or GitLab. All right. So let's talk about how you can set up your remotes in Visual Studio Code.
11:00
Well, one, when you get in clone or if you clone a repository, which you can do from the command line or command palette, rather, excuse me, you can say git clone.
11:08
And then you would paste in the repository clone. Whether you're doing it by HTTPS or SSH from GitHub, you can do it that way.
11:16
Or if you're signed into your GitHub account in Visual Studio Code, you can choose this other option clone from GitHub.
11:22
I'm going to go with this one for this case. I've already have it available. I've already cloned this locally.
11:26
But if you hit enter on this, it would step you through the process.
11:29
It would pull down all the assets from the remote instance of that repository locally to your machine.
11:34
And then you can begin working on that project more. So because I cloned it from that remote Visual Studio Code behind the scenes.
11:41
I already set that up as my remote for me. If I want to manage that though a bit further, I can bring up the command palette again.
11:49
And I can say I want to add another remote.
11:51
Maybe there's another fork of that repository under my personal account versus one under Cecil's personal GitHub account.
11:59
And I want to use that as one remote and push changes there before I push them over to Cecil's.
12:04
Because maybe I don't have permission to push to Cecil's repository directly. And instead I got to push to my own.
12:10
So I can change the remote to be that fork instance of it and so forth. Or maybe I need to remove a remote. Maybe I'm done working on that project.
12:17
That type of thing. I can go ahead and do that.
12:19
I hit enter and it shows the options of which remote repositories I can remove that I have active within this project in Visual Studio Code.
12:28
In this case, it's just the one. It's the origin one that I have from GitHub.
12:32
So as you can see, like there's tons of different things that we can do related to source control, related to Git inside of VS Code.
12:39
And I know we just kind of ran through a whole bunch of different things.
12:42
But the main point of this video was to make you understand that whether you're using the command line or you're using some of the built-in menus or the command palette,
12:51
you have different options and Visual Studio Code is here to help you as you're trying to navigate your GitHub workflow.
12:57
Now, in the next video, we're going to go a little bit more in depth in terms of viewing changes and showing you how Visual Studio and some of the built-in things inside of the editor makes it much more apparent and really nice.
13:08
so you can see exactly what's happening inside of your repository.