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
OK
button. We now have a.git
directory in our project root directory.In Project Tool window, right-click on the
epc.py
file.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
Project
tool window, right-click on the root folder.Choose
New -> File
.Provide
requirements.txt
and 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:flask
Close
requirements.txt
by clicking thex
on the tab.Commit these changes to VCS with
VCS -> Commit Changes
.Type
First commit
in theCommit Message
box.Click the
Commit
button, then chooseCommit
from the button menu.Note that the two files in the
Project
tool window are now a normal color.Open PyCharm’s Settings with
File -> Settings
, or useCtrl-Alt-S
as a shortcut. (macOS:PyCharm -> Preferences
andCmd-,
.)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
Cancel
to 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
.git
directory in the the file browser? - What other hidden directory did PyCharm make in the root directory?
- Can PyCharm help you manage your
.gitignore
file? - 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