Pycharm version control как настроить

Enable version control

PyCharm supports version control integration at two levels:

At the IDE level, VCS integration is provided through a set of bundled plugins enabled by default.

At the project level, VCS integration is enabled by associating project folders with one or several version control systems.

Associate a project root with a version control system»

PyCharm allows you to quickly enable your project’s integration with a version control system, and associate it with the project root. For instructions on how to associate separate project directories with different version control systems, refer to Associate a directory with a version control system.

Press Alt+` to open the VCS Operations Popup and select Enable Version Control Integration .

Alternatively, from the main menu, select VCS | Enable Version Control Integration .

In the Enable Version Control Integration dialog that opens, select a version control system from the list that you want to associate with your project folder.

After VCS integration is enabled, PyCharm will ask you whether you want to share project settings files via VCS. You can choose Always Add to synchronize project settings with other repository users who work with PyCharm.

Notification prompting to select how to treat configuration files

Note, that this only applicable to Git and Mercurial.

Associate a directory with a version control system

PyCharm supports a directory-based versioning model, which means that each project directory can be associated with a different version control system.

Press Ctrl+Alt+S to open the IDE settings and select Version Control | Directory Mappings .

The Directory Mappings page shows a list of project directories and version control systems associated with them (if no directories have been added, the list only contains the project root).

Click the Add button on the right.

In the Add VCS Directory Mapping dialog that opens, select the Directory option. Type the path to the directory that you want to associate with a version control system, or click the Browse button and select the directory in the dialog that opens.

From the VCS list, select the version control system that will be used to control the files in this directory. Note that this list only contains the version control systems for which the corresponding plugins are currently enabled.

Click OK to save the mapping and return to the Directory Mappings page.

Manage unregistered directories

For projects with Git or Mercurial integration enabled, PyCharm scans project directories to check if there are Git/Mercurial repositories that are not controlled by the IDE. If such repositories are detected, PyCharm displays a notification.

To add an unregistered root, click the Add roots link in the notification. Alternatively, open the Version Control settings page, select the unregistered root you want to add (they are marked grey) and follow the procedure Associate a directory with a version control system.

If you do not want to be notified about these roots again, click the Ignore link in the notification. Note that if new unregistered repositories are added to the project, PyCharm will notify you about them.

Change VCS associations

Press Ctrl+Alt+S to open the IDE settings and select Version Control | Directory Mappings .

The Directory Mappings page shows a list of project directories and version control systems associated with them (if no directories have been added, the list only contains the project root).

Locate the row that corresponds to the directory which you want to put under another version control system.

Click the VCS column. From the list that appears, select a new version control system.

If you select None , VCS integration for the selected directory will be disabled.

Pycharm – интеграция контроля версий

PyCharm поддерживает различные системы управления Subversion. Эта функция помогает улучшить кодовую базу, управляя различными версиями вместе. В этой главе подробно говорится об этой концепции.

Вовлеченные шаги

Вам нужно будет выполнить следующие шаги для инициализации и управления системой контроля версий –

Инициализация системы управления Subversion

Чтобы систематически запускать систему контроля версий, важно ее инициализировать. В PyCharm доступны различные опции для разных систем контроля версий.

Система контроляКонтроль версий

Игнорирование файла

В любом проекте PyCharm, в котором мы настраиваем проект по умолчанию и виртуальную среду в нем, мы также должны создавать его управление с помощью системы контроля версий. Например, Git включает в себя файлы .gitignore, которые игнорируются во время операции фиксации, однако включает в себя некоторые из его конфигураций. Теперь перейдите в меню «Настройки» и проверьте следующее:

Игнорирование файла

Он включает в себя различные конфигурации для проверки пути исполняемого файла Git и проверки, игнорируются ли какие-либо файлы.

Игнорируемый файл

Конфигурация GitHub

PyCharm включает в себя настройки, которые включают конфигурацию репозитория GitHub, где пользователь может включать имя пользователя, пароль и другие учетные данные, если таковые имеются.


Как только вы закончите с упомянутыми настройками, вы можете напрямую добавить и зафиксировать локальные изменения в репозитории Git.

PyCharm Integration with GitHub

Setting up Version Control for Collaboration Projects

PyCharm is arguably one of the most popular IDEs used by developers on AI / Machine Learning projects. It is a full-featured IDE well suited for professional Python programming. It is available in 2 editions:

  • PyCharm Professional Edition which is a paid software after a 30-day free trial period
  • PyCharm Community Edition which is free, and this is the version that I currently have on my system

Good amount of information about these can be found at the below location:

PyCharm: the Python IDE for Professional Developers by JetBrains

Save time while PyCharm takes care of the routine. Focus on the bigger things and embrace the keyboard-centric approach…

However in this discussion our focus is to set up Collaboration projects using PyCharm and GitHub.

As the first step, login into GitHub with your user ID, and create a Repository as shown below. Here we create a new Private Repository.

Now lets set-up a secure encrypted communication between the PyCharm IDE & the GitHub Repository. To ensure that your PyCharm IDE can access your GitHub Repository, you must generate a Personal Access Token from here. The scopes gist, read:org, and repo are the minimum that must be granted to the access token. Any additional scopes can be granted as per requirement.

On clicking Generate Token, a new access token is generated. Copy its GUID. This GUID shall be used when setting-up Version Control in PyCharm. In PyCharm go to File Menu→ Settings → Version Control → GitHub. Select the option of logging into GitHub using Token, and enter the GUID here (using the option of logging-in using Token instead of credentials is also beneficial when collaborating with other developers. In such a case everyone can simply use the same token for login, and the GitHub credentials of one user need not be shared). Also, select the option to Clone Git repositories using SSH.

Now PyCharm is permitted to access your GitHub Repo, but we still need to technically enable the secure encrypted exchange via SSH. Unless this is done, it will not be possible to Clone the Repository or Push code changes to it. Most commonly the error would be similar to: Error: Permission denied (publickey). This means that the server rejected your connection request. Open Git Bash which provides the Git Command line. Verify your connection by typing:

Verify that you have a private key generated and loaded into SSH by typing:

The system should ideally print out a string of numbers and letters. If it does not print anything, you will need to generate a new SSH key & associate it with GitHub.

If you do end up needing to generate a new SSH key, type the below command substituting your GitHub email address:

Now the generated key needs to be added to the SSH agent. Remember, this step is only needed if the earlier check did not return any key already loaded into SSH. Start the ssh-agent and add your SSH private key to it by typing:

The last thing remaining now is to configure your GitHub account to use your new (or existing) SSH key. For this, Copy the SSH key to clipboard:

In your GitHub Account settings, go to SSH & GPG Keys. Here, add the new SSH Key by Paste-ing it from clipboard.

This completes the steps for integration of GitHub Repo with PyCharm. To clone the GitHub Repository created in the first step, open PyCharm → Go to Menu VCS → Get from Version Control → Select GitHub → Select the Repo to clone, and Confirm.. and That’s it ! You are ready to roll ! :).

PyCharm Git Integration

Before we head into the details, let’s understand what a version control system is. VCS belong to a category of software tools that help programmers manage changes to the software over time. These changes are always kept on track, denoted by letters or numbers in the version control system. This allows software teams to compare source codes, identify differences, and create revisions before writing any new software. Besides, you can also keep a note of which version of the application is currently in development or needs one.

Git and GitHub

Git and GitHub are two terminologies that most software developers confuse nowadays. Git is a version control software but comes in the form of a tool that lets you manage the history of your source code whereas GitHub is a hosting service for projects that use Git.

You don’t need a GitHub account to use Git. You can use it independently along with IDEs. Whereas for GitHub, you will need a git repository to control and track tasks, its bugs, and feature requests. It allows sharing your repositories; accessing others’ and storing remote copies of your repositories as a backup on the GitHub servers.

Integrating Git in PyCharm

The tutorial below will guide on how to integrate PyCharm’s Git features. Instead of performing Git related task independently in a command terminal, PyCharm lets you perform them in the IDE and later link it to your GitHub account.

1. How to install and configure Git?

To be able to use Git for PyCharm, do the following:

    • Download the tool from here. The supported version for Windows is 2.4 and for Linux and MacOS is
    • Next, from the Settings/Preferences dialog on the main toolbar of your IDE, select VersionControl and then click on Git from the left pane.
    • Specify the path to the file where Git executable is.
    • Set a password for your remote Git repository. This is because every time you use a remote git repository, it asks for authentication.
    • From the Settings tab, select AppearanceandBehaviour.
    • Now, click System Settingsand then choose Passwordson the left.
    • PyCharm processes passwords for remote Git repositories in several ways:
      • I. Native Keychain: This option uses Native Keychain to store your passwords. It is only available for Mac and Linux OS.
      • II. KeePass: This option lets you store passwords in a file that are only accessible through a master password. To do that, enter a password in the Master Password Field that will be used to access the c.kdbx file.
      • III. Do not save: This option is available when you want PyCharm to reset your passwords every time you close it.
      2. How to Create a Local Git Repository

      To create a local Git Repository, follow the procedures below:

      • First, to link your GitHub account with PyCharm. Go to File -> Settings -> VersionControl -> GitHub
      • Enter your GitHub username and password to log in.
      • Now, create a new PyCharm project. Click File -> NewProject
      • Now, for the local repository, go to VCS -> ImportintoVersionControl -> CreateGitRepository.
      • Once created, you will see a directory named ‘.git’ in the project directory. To test your repository, go to File -> Settings -> VersionControl -> Git -> Test
      3. How to Add and Commit Files to the Git Repository
      • To create a python file, right click on the project that you just created from the Project Menu and select New -> Python
      • Next, PyCharm will ask you if you want this file to be added into your repository. If you click on ‘Yes’, you will be able to commit and track all the changes you will make to this file.

      • To commit this file to the repository. Right click on the python file, select Git -> CommitFile.Note: The file name in your project menu will appear green unless you don’t commit the file. Once you’re done adding the file, you can make changes and commit them. Soon after the changes, the file name in the menu will change colors to blue.
        • After that, you will be prompted with a Commit Changes window on your IDE.
        • To keep track of what changes you have made in the past, double click the filename, and you will see the code in green.
        • Lastly, you can now to go to the VersionControl menu right at the bottom of the window to see a variety of other features. This includes a Log that stores all the changes you will make in the particular local repository.
        4. How to Add a Remote Repository?

        In addition to working on a local repository, you can also create remote repositories to collaborate with developers from all around the world. These will help to fetch and push data whenever you need to share your work.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *