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.
Python Source Control Management (Git) in VS Code
VS Code has built in support for source control management. In this lesson, you’ll learn how to work with VS Code’s robust source control features such as:
- Staging files
- Making commits
- Pushing to and pulling from remote repos
- Viewing diffs
Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in thediscussion section and let us know.
00:00VS Code has robust source control capabilities.You can commit files,push and pull them from remote repositories, checkout and create branches,fix merge conflicts, and view diffs.
00:14It has support for Git and GitHub built-in,and if you need to use something else,there’s probably an extension for it in the Marketplace.I’m going to start by opening up a new integrated terminal, just like this,and I’m going to use this to clone a private repository I have on my GitHubaccount.
00:32My repo contains a very trivial little Python module that exposes functions foradding and subtracting numbers,similar to what we saw before. Now that I’ve cloned my repo,I’ll change directory into it, just like normal. Now in VSCode I’ll press Command + Oto open a folder and I’ll select my repo folder on the desktop.
00:55If we take a look at myoperations.py file,you’ll see what I mean by this being a very trivial module,but it works for demonstration purposes.
01:05I’ll selectFile >New File,and I’ll call thisprogram.py and I’ll make sure that I’m saving it into mylocal repo directory. Let’s see what’s going on with our Git status.
01:18I could either rungit status down here in the integrated terminal,or I can see what’s being displayed in the source control sidebar.Let’s click on this icon that looks like a fork,and now we see on the left that we have all of our files with changes.
01:35ThisU means that our file is unstaged,which makes sense because we’ve just created it. To stage the file, hover over thename and click on the little plus icon.
01:47And now you see that the file has moved toSTAGED CHANGESand it has anA, meaning that it’s been added. In our program here,I will quickly import theoperations moduleand now I will print out the result of calling theadd() function with twonumbers. And just to make sure this works,I will run this file in the integrated terminal and we’ll see our expectedoutput.
02:13Perfect. Notice on the left that this file is appearing underCHANGES.That’s because we’ve changed the file. TheM stands for modified.
02:24Once again, I’ll click the plus to stage these changes,and now I can enter a commit message up here. So I’ll just give ita basic commit message here,and now I can click on this little check mark to commit these changes,and you’ll see that they disappear from the list.
02:42If we click on More Options up here in the top-right corner,you’ll see that we have lots and lots of different commands that we can run.But just to keep things simple,I’ll click on this little button down here in the bottom-left corner.
02:57This will automatically push and pull changes from the remote server. And I’llclick onOK. Just to show that this worked,I’ll move over to our integrated terminal and we’ll run a good old-fashionedgit status.
03:13Once I press Enter, we see that we havenothing to commit.
03:17Our changes have been pushed to the remote repository.But now, if we switch to theoperations module,you’ll see that we didn’t ever actually use our subtraction function.
03:28I’ll select the whole thing and press Delete,and now you’ll see that this file shows up underCHANGES. If I click on it,VS Code will show me the differences. As you can imagine,this is extremely helpful.
03:44That’s how to perform some common source control tasks in Visual Studio Code.For the most part,everything else related to source control works just like it doesin other editors. In this video series,you learned what Visual Studio Code is, how to find and install extensions,how to work with folders and workspaces,how to run and debug programs, how to work with unit tests,and finally, how to work with some of VS Code’srobust source control features. Like with most large open-source softwareprojects, there are tons of little features riddled throughout the software.
04:22I learn something new all the time. I encourage you to download VS Codeif you haven’t already and play around with it.
04:30If there’s a feature that you want and you can’t find out how to do it,search for it in the Extensions Marketplace.If you still can’t figure out how to make the editordo what you want and Google searchingisn’t helping, head over to the GitHub repository for VS Code and submit afeature request to the engineers.
04:49Just make sure that you read the contributing guidelinesfirst. I’m Austin Cepalia with realpython.com,and I wish you the best of luck on your programming endeavors. Happy coding!
joseph onApril 6, 2019
Absolutely fantastic. Thanks for whipping this up and sharing.
Daniel onApril 6, 2019
Great course. Helped to see it all in action and then go through the supporting materials alongside the course.

Austin CepaliaRP Team onApril 7, 2019
Thanks, glad you both liked it! I design my courses so that they complement the written tutorials, sometimes adding in extra bits of information or different examples to help clarify a concept. Video + written content go hand-in-hand :)
DD onApril 7, 2019
Would be great to get any optimizations for running python debugging as my vs code currently takes ~2-5 seconds every time i run it.. which doing so regularly is super slow !
Also how can i get other unittest modules (pytest) working as efficiently as you have unittest working ?
Thanks
Sciencificity onApril 15, 2019
Thanks so much! This was awesome, I am sure to not go back to my previously used editor!
Pavel Krejsa onApril 23, 2019
Hi, thanx a lot for this beginners intro. I would be very happy if you extend it with “virtualenv” like environment with different pip packages per environment.
stephenm onJune 1, 2019
Great course! Would be nice to add a video on how to setup/config/use virtual environments with VS code
JVargas onJune 5, 2019
git source control is just a click away.
Subhash Bhushan onNov. 14, 2019
All Git-based source code repositories out there - Github, Gitlab, BitBucket - would work by default. If you use Mercurial, you could install thevscode-hg extension.
qmark42 onFeb. 1, 2020
I thought that I could do fair in Python coding but have since found that I am a “mid-beginner.” I will be downloading VS. but I expect to come back to this course in the future.
Thanks much to Austin and Real Python.
Lokman onMarch 12, 2020
Thanks @Austin Cepalia, last time I’m using Vim editor and bash. After start learned Vscode looks like editor IDE make things easier.
Ray Leiter onMarch 27, 2020
This video doesn’t appear to me to be a “beginners” video.I mistakenly thought this video was going to concentrate on how to setup the interface for a more productive use of the edit/run cycle.Material like the use of source control techniques and the debug facilities, I believe would be part of an additional video.Also, I think many tutorial authors are somewhat disingenuous when they use a particular operating environment but make the claim that it should be the same as other operating environments.
rickecon onApril 11, 2020
Great course. Thank you.
Aparna onApril 26, 2020
Much needed content to get started with VS code. thanks
tsusadivyago onMay 19, 2020
I am going to try vs code now, great tutorial
Ranjith onMay 25, 2020
Really good tutorial. Thank you. I think I will start using VS Code.
Alain Rouleau onJuly 20, 2020
Thanks for the tutorial. Learned quite a lot and VS Code is now my editor of choice. Tried other IDEs like PyCharm but much prefer VS Code since it’s not so bloated.
Grouchy Old Fart onOct. 11, 2023
I had to bail on this one. I don’t know if this is a difference between Mac and Windows, or if VS Code has changed a great deal in the last four years, or if I am doing something wrong. Whatever the problem is, much of it doesn’t work as advertised.
There is a chance this is way over my head as well.
eyesnight00 onFeb. 11, 2024
This is 5 years old and the video could do with being updated as VS Code has a few changes.

Bartosz ZaczyńskiRP Team onFeb. 12, 2024
@eyesnight00 Noted! Do you have any particular suggestions for the updates you’d like to see?
rwelk onFeb. 20, 2024
Very informative I liked the info in this video. I have applied the code snippet extension and played with it, works well. Thank you!
Become a Member to join the conversation.
Course Contents

