Start Version Control¶
PyCharm’s Project tool is a very smart folder browser. We’ll show
this by putting our Todo app under version control and seeing how
PyCharm can do work for us, with colors indicating VCS status. We
also show how PyCharm works with Python requirements.
Source for this step | View video/audio walkthrough
Steps¶
From the PyCharm menus, select
VCS -> Import into Version Control -> Create Git Repository.In the popup window, select the project directory and click the
OKbutton. We now have a.gitdirectory in our project root directory.In Project Tool window, right-click on the
epc.pyfile.At the moment, it is red, meaning, not under version control.
In right-click context menu, choose
Git -> Add to VCS.The color changes to green, indicating it is added but not committed.
In
Projecttool window, right-click on the root folder.Choose
New -> File.Provide
requirements.txtand clickOk.In the next dialog, accept adding the new file to VCS.
In
requirements.txt, add a line forflask. The file should look like this:requirements.txt for Start VC section¶flaskClose
requirements.txtby clicking thexon the tab.Commit these changes to VCS with
VCS -> Commit Changes.Type
First commitin theCommit Messagebox.Click the
Commitbutton, then chooseCommitfrom the button menu.Note that the two files in the
Projecttool window are now a normal color.Open PyCharm’s Settings with
File -> Settings, or useCtrl-Alt-Sas a shortcut. (macOS:PyCharm -> PreferencesandCmd-,.)In Settings (aka Preferences), click on
Tools -> Python Integrated Tools. The first field shows which file is registered with PyCharm as this interpreter’s requirements file.Click
Cancelto dismiss the preferences.
Analysis¶
We did a lot of small steps in this task, showing how the tool windows can be put to work:
- Visual cues. Making a local Git repository caused the project tool to start giving us helpful visual information.
- Tool context menus. Entries in the project tool can be right-clicked on to get context sensitive menus.
- Git. PyCharm is a great visual front-end for version control systems (VCS).
Extra Credit¶
- Why doesn’t PyCharm show the
.gitdirectory in the the file browser? - What other hidden directory did PyCharm make in the root directory?
- Can PyCharm help you manage your
.gitignorefile? - What is the keyboard shortcut for committing a file?
- How do you delete a file from the filesystem and from VCS?
- Besides the project tool window, where else does the color for a file’s VCS status appear?
- What is the color for a file that has uncommitted changes?
- What is the visual indicator on a project tool’s file when it has a major Python error in it?
- When installing a Python package via Project Interpreter preferences,
can you simultaneously record it in the
requirements.txt?
- Previous topic: Rename View
- Next topic: Rename Files