PyCharm 2018.2 Help

Manage projects hosted on GitHub

PyCharm allows you to manage projects controlled by Git that are hosted on GitHub without leaving the IDE.

Register a GitHub account in PyCharm

To retrieve data from a repository hosted on GitHub, and to be able to share your projects, you need to register your GitHub account in PyCharm.

In either case, you can configure PyCharm to save your credentials so that you do not have to specify them each time you retrieve data from a remote, or push your commits (see Configure a password policy).

Register an existing account

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), select Version Control | GitHub in the left pane.

  2. Click Add account.

  3. In the dialog that opens, specify your GitHub server URL (either, or an enterprise instance).

  4. Do one of the following:
    • If you already have a token, click the Enter token link and paste it there.

    • If you want to obtain a new token, enter your login and password.

      Note that if you have two-factor authentication enabled, you will be asked to enter a code that will be sent to you by SMS or through the mobile application.

Create a new GitHub account

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), select Version Control | GitHub in the left pane.

  2. Click Add account, and in the dialog that opens, click Sign up for Github.

  3. On the Sign up for GitHub page that opens in the browser, choose the account plan (free or paid), and specify the requested information. When you are done creating an account, the GitHub Welcome Page is displayed.

  4. Return to GitHub settings and specify your credentials for PyCharm to register them.

Manage multiple accounts

PyCharm allows you to specify multiple GitHub accounts. This can be useful, for example, if you are working on an open-source project using your personal account, and doing work for a company with a corporate account.

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), select Version Control | GitHub in the left pane.

  2. Use the icons general add svg button to add as many accounts as you need.

  3. To set an account as a default one for the current project, select it and click platform impl com intellij ide ui laf icons checkmark. If a default account is set, PyCharm will not ask you to select an account you want to use when you share your project on GitHub, rebase a fork, create a pull request, or create a gist.

Checkout a project from GitHub

PyCharm allows you to check out (clone) a repository from GitHub and create a new project based on it.

  1. From the main menu, choose VCS | Checkout from Version Control | Git.

  2. In the Clone Repository dialog that opens, specify the URL of the repository that you want to clone, or select a repository from the list that contains all GitHub projects associated with your account and the organization that your account belongs to.

  3. In the Directory field, specify the path where the folder for your local Git repository will be created into which the remote repository will be cloned.

  4. Click Clone. If you want to create a PyCharm project based on the sources you have cloned, click Yes in the confirmation dialog. Git root mapping will be automatically set to the project root directory.

Share a project on GitHub

You can add a remote repository for your project on GitHub.

  1. Open the project you want to share.

  2. From the main menu, choose VCS | Import into Version Control | Share Project on GitHub.

    If you have already registered your login and password in PyCharm, connection to GitHub will be established using these credentials.

    If you have not registered your GitHub credentials in PyCharm, the Login to GitHub dialog opens. Specify your access token or request a new one with your login and password.

  3. When connection to GitHub has been established, the Share Project on GitHub dialog opens. Specify the new repository name, the name of the remote (for example, the repository that will be hosted on GitHub and that you will sync your local repository with), and enter a description of your project's main functionality.

    You can select the Private option if you do not want to allow public access to your repository for other GitHub users (note that this option is unavailable for free accounts).

  4. Click Share to initiate a new repository and upload project sources to it.

Contribute to somebody else's projects

If you want to contribute to a project hosted on GitHub that you do not have rights to push to, follow this workflow:

  • Create a fork of the project you want to contribute to, for example, a copy of the original repository on GitHub.

  • Clone this fork to create a local repository.

  • Make changes to your copy of the original project.

  • When you are ready to share the results of your work, rebase your fork on the current HEAD of the master branch in the original project to make sure your changes do not conflict with new commits that were pushed after you created your fork.

  • Create a pull request so that you can tell others about the changes you've made, and ask for comments or review. Note that a pull request is merged into the original repository only after approval.

Fork a project

  • Open the project that you want to fork on GitHub and click github fork

A copy of the original project will be created under your account. To make changes to this project, you need to clone it to create a local repository.

Watch this video tutorial on how to keep your fork of a project up to date:

Rebase a fork

  • From the main menu, choose VCS | Git | Rebase my GitHub fork. Your fork will be rebased onto the HEAD commit in the master branch of the original project your created your fork from.

Create a pull request

By creating a pull request, you tell others about the changes you've pushed to your fork, so that they can be reviewed, discussed, and integrated into the base branch. To create a pull request, do the following:

  1. From the main menu, choose VCS | Git | Create Pull Request. The Create Pull Request dialog opens.

  2. Under Base Fork, specify the project that you want to send the pull request to. Either select a repository from the list populated by PyCharm, or click Select Other Fork.

  3. Under Base Branch, specify the branch in the target project that your changes will be applied to. Click Show Diff to review the list of commits that will be included in the pull request. To view the details of a commit, select it and switch to the Log tab of the Version Control tool window, where you can see a list of files included in the selected commit, view diff, etc.

  4. Specify the name for your pull request in the Title field, and, optionally, provide a description of the changes to be applied through your request.

Share code by using gists

Gists allow you to share your code. You can share code snippets, entire files, or even applications. You can also use gists to save and share console output when running, debugging, or testing your code.

Create a gist

  1. Select a code fragment in the editor, or files and folders in the Project tool window. To save console output to a gist, right-click anywhere in the tool window or tab that contains that output.

  2. On the context menu of the selection, choose Create Gist.

  3. In the Create Gist dialog that opens, specify the name for your gist under Filename, and enter a description of the code you are going to publish.

  4. Select the Secret option to create the so-called secret gist. Secret gists are not searchable and do not show up in Discover. They can only be used for your own purposes, as you cannot share them.

    If you want to create a public gist, make sure this option is deselected. Public gists are searchable, and they show up in Discover where people can browse newly appearing gists. Use public gists if you want other people to be able to find and see your code.

  5. If you want to open the newly created gist in your default browser, select the Open in browser option and click OK.

Jump to the GitHub version of a file

You can jump from PyCharm to the GitHub version of a file. PyCharm detects which branch is currently active as well as the latest revision of the file, and opens the GitHub copy of the selected file in the corresponding commit in your web browser. If you are opening the GitHub file version from the editor, the file will be also automatically scrolled to the current line.

  • Select a file in the editor or in the Project view, and choose Open on GitHub from the context menu or from the Ctrl+Shift+A popup. The remote version of the file in will open in the browser.

    If the file points to more than one remote, you will be prompted to select the appropriate repository.

Last modified: 21 November 2018