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

  1. From the PyCharm menus, select VCS -> Import into Version Control -> Create Git Repository.

  2. In the popup window, select the project directory and click the OK button. We now have a .git directory in our project root directory.

  3. In Project Tool window, right-click on the epc.py file.

  4. At the moment, it is red, meaning, not under version control.

  5. In right-click context menu, choose Git -> Add to VCS.

  6. The color changes to green, indicating it is added but not committed.

  7. In Project tool window, right-click on the root folder.

  8. Choose New -> File.

  9. Provide requirements.txt and click Ok.

  10. In the next dialog, accept adding the new file to VCS.

  11. In requirements.txt, add a line for flask. The file should look like this:

    requirements.txt for Start VC section
    flask
    
  12. Close requirements.txt by clicking the x on the tab.

  13. Commit these changes to VCS with VCS -> Commit Changes.

  14. Type First commit in the Commit Message box.

  15. Click the Commit button, then choose Commit from the button menu.

  16. Note that the two files in the Project tool window are now a normal color.

  17. Open PyCharm’s Settings with File -> Settings, or use Ctrl-Alt-S as a shortcut. (macOS: PyCharm -> Preferences and Cmd-,.)

  18. 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.

  19. 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

  1. Why doesn’t PyCharm show the .git directory in the the file browser?
  2. What other hidden directory did PyCharm make in the root directory?
  3. Can PyCharm help you manage your .gitignore file?
  4. What is the keyboard shortcut for committing a file?
  5. How do you delete a file from the filesystem and from VCS?
  6. Besides the project tool window, where else does the color for a file’s VCS status appear?
  7. What is the color for a file that has uncommitted changes?
  8. What is the visual indicator on a project tool’s file when it has a major Python error in it?
  9. When installing a Python package via Project Interpreter preferences, can you simultaneously record it in the requirements.txt?