Перейти к содержимому

Как связать pycharm с github

  • автор:

Добавление проект в репозиторий

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

В репозитории можно отображать необходимые проекты. Можно вывести только те проекты, владельцы которых являются владельцами репозитория.

Чтобы участники репозитория могли увидеть проект, для них должна быть настроена видимость. Дополнительные сведения см. в разделе «[AUTOTITLE» и «Управление видимостью проекты](/issues/planning-and-tracking-with-projects/managing-your-project/managing-access-to-your-projects)».

  1. На портале GitHub перейдите на главную страницу своего репозитория.
  2. Щелкните

Снимок экрана: вкладки репозитория. Вкладка

Projects.

Set up a Git repository

When you clone an existing Git repository or put an existing project under Git version control, PyCharm automatically detects if Git is installed on your computer. If the IDE can’t locate a Git executable, it suggests downloading it.

PyCharm supports Git from the Windows Subsystem for Linux 2 (WSL2), which is available in Windows 10 version 2004.

If Git is not installed on Windows, PyCharm searches for Git in WSL and uses it from there. Also, PyCharm automatically switches to Git from WSL for projects that are opened when you use the \\wsl$ path.

If you need to manually configure PyCharm to use Git from WSL, go to the Version Control | Git page of the IDE settings Control+Alt+S , click the Browse icon in the Path to Git executable field, and select Git from WSL via the \wsl$ path, for example, \\wsl$\debian\usr\bin\git .

Check out a project from a remote host (git clone)

PyCharm allows you to check out (in Git terms, clone ) an existing repository and create a new project based on the data you’ve downloaded.

Getting a project from GitHub

  1. To start cloning a Git repository, do one of the following:
    • If the version control integration is already enabled, go to Git | Clone .
    • If the version control integration is not enabled yet, go to VCS | Get from Version Control . Alternatively, go to File | New | Project from Version Control .
    • If no project is currently open, click Get from VCS on the Welcome screen.
  2. In the Get from Version Control dialog, specify the URL of the remote repository you want to clone or select one of the VCS hosting services on the left. If you are already logged in to the selected hosting service, completion will suggest the list of available repositories that you can clone.
  3. Click Clone . If you want to create a 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. If your project contains submodules, they will also be cloned and automatically registered as project roots.
  4. In the Trust and Open Project »? project security dialog, select the way you want to open the project: Trust Project or Preview in Safe Mode .

Put an existing project under Git version control

You can create a local Git repository based on the existing project sources.

Associate the entire project with a single Git repository

Notification prompting to select how to treat configuration files

  1. Open the project that you want to put under Git.
  2. Press Alt+` to open the VCS Operations Popup and select Enable Version Control Integration . Alternatively, go to VCS | Enable Version Control Integration .
  3. Choose Git as the version control system and click OK . The entire project will then be associated with a single Git directory, so there is no need to add each file to the Git directory individually.
  4. 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.

If there is no Enable Version Control Integration option available in the VCS Operations Popup , it means that Git version control is already enabled for the project.

Associate different directories within the project with different Git repositories

  1. Open the project that you want to put under Git.
  2. In the main menu, go to VCS | Create Git Repository .
  3. In the dialog that opens, specify the directory where a new Git repository will be created. Git does not support external paths, so if you choose a directory that is outside your project root, make sure that the folder where the repository is going to be created also contains the project root.
  4. If you are creating multiple Git repositories inside the project structure, repeat the previous steps for each directory.

After you have initialized a Git repository for your project, you need to add project files to the repository.

Add files to the local repository

  1. In the Commit tool window Alt+0 , expand the Unversioned Files node.
  2. Select the files you want to add to Git or the entire changelist and press Control+Alt+A or choose Add to VCS from the context menu. You can also add files to your local Git repository from the Project tool window: select the files you want to add, and press Control+Alt+A or choose Git | Add from the context menu.

When Git integration is enabled in your project, PyCharm suggests adding each newly created file under Git, even if it was added from outside PyCharm. You can change this behavior in the Version Control | Confirmation page of the IDE settings Control+Alt+S . If you want certain files to always remain unversioned, you can ignore them.

If you attempt to add a file that’s on the .gitignore list, PyCharm will suggest force-adding it. Clicking Cancel in the confirmation dialog only cancels force-adding ignored files – all other files will be added to the Git repository.

Exclude files from version control (ignore)

Sometimes you may need to leave certain files unversioned. These can be VCS administration files, artifacts of utilities, backup copies, and so on. You can ignore files through PyCharm, and the IDE will not suggest adding them to Git and will highlight them as ignored.

You can only ignore unversioned files, that is, files that you see in the Unversioned Files changelist. If a file is added to Git but not committed, you can right-click it in the Changes view and choose Rollback .

Git lets you list ignored file patterns in two kinds of configuration files:

  • .git/info/exclude file. Patterns listed in this file only apply to the local copy of the repository. This file is created automatically when you initialize or check out a Git repository.
  • One or more .gitignore files in the VCS root directory and its subdirectories. These files are checked into the repository so that the ignore patterns in them are available to the entire team. Therefore, it is the most common place to store the ignored file patterns. If there is no .gitignore file in the VCS root directory, you can right-click anywhere in the Project tool window, choose New | File , and type .gitignore in the New File dialog. To create a .gitignore file in Windows Explorer, create a file named .gitignore. and Windows will rename it automatically to .gitignore .

Add files to .gitignore or .git/info/exclude

  1. Decide what kind of Git configuration file you are going to use to ignore files. If in doubt, use .gitignore .
  2. Locate the unversioned file or folder you want to ignore in the Changes view or in the Project tool window. File colors in these views help you identify the status of the file.
  3. Right-click the selection and choose Git | Add to .gitignore or Git | Add to .git/info/exclude . File colors in these views help you identify the status of the file.

If you need to exclude files by a certain pattern or type, you can edit the .gitignore or .git/info/exclude file directly. See .gitignore patterns format.

If you want ignored files to be also displayed in the Changes view, click on the toolbar and select Show Ignored Files .

Add a remote repository

If you created a Git repository based on local sources, you need to add a remote repository to be able to collaborate on your Git project, as well as to eliminate the risks of storing your whole codebase locally. You push changes to a remote repository when you need to share your work and pull data from it to integrate changes made by other contributors into your local repository version.

If you have cloned a remote Git repository, for example, from GitHub, the remote is configured automatically, and you do not have to specify it when you want to sync with it. The default name Git gives to the remote you’ve cloned from is origin .

Define a remote

  1. Create an empty repository on any Git hosting, such as Bitbucket or GitHub. You can create a repository on GitHub without leaving PyCharm: see Share a project on GitHub.
  2. Invoke the Push dialog when you are ready to push your commits by selecting Git | Push from the main menu, or press Control+Shift+K .
  3. If you haven’t added any remotes so far, the Define remote link will appear instead of a remote name. Click it to add a remote.
  4. In the dialog that opens, specify the remote name and the URL where it will be hosted, and click OK .

Add a second remote

In some cases, you also need to add a second remote repository. This may be useful, for example, if you have cloned a repository that you do not have write access to and are going to push changes to your own fork of the original project. Another common scenario is that you have cloned your own repository, which is somebody else’s project fork, and you need to synchronize with the original project and fetch changes from it.

  1. In the main menu, go to Git | Manage Remotes . The Git Remotes dialog will open.
  2. Click the Add button on the toolbar or press Alt+Insert .
  3. In the dialog that opens, specify the remote name and URL and click OK .
  • To edit a remote (for example, to change the name of the original project that you have cloned), right-click the remote branch in the Branches pane of the Git Log tool window and select Edit Remote from the context menu. You can also edit a remote from the Push Dialog by clicking its name.
  • To remove a repository that is no longer valid, right-click it in the Branches pane of the Git Log tool window, and select Remove Remote from the context menu.

Learn more from this video:

GitHub

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

If you do not want to specify your credentials each time you sync with a remote, or push your commits, you can configure PyCharm to save your account information (refer to Configure a password policy).

Register an existing account by signing in to GitHub

  1. Press Control+Alt+S to open the IDE settings and then select Version Control | GitHub .
  2. Click .
  3. Select Log In via GitHub .
  4. Enter your GitHub credentials in the browser window that opens. 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.

Register an existing account with a token

Adding GitHub account with token

  1. Press Control+Alt+S to open the IDE settings and then select Version Control | GitHub .
  2. Click .
  3. Select Log In with Token .
  4. Do one of the following:
    • If you already have a token, insert it in the Add GitHub Account dialog window:
    • If you want to obtain a new token, click Generate . Enter your GitHub credentials in the browser window that opens. 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. In the token generation page, make sure that the repo , the gist and the read:org scopes are enabled (refer to Understanding scopes). Click Generate token , copy the token, and paste it into the Add GitHub Account dialog window.
  5. Click Add Account

See Creating a personal access token for more details on GitHub tokens.

Update an expired token

  1. When your token expires, you see the following warning when trying to push changes to the GitHub repository: Expired token warningClick Use Token .
  2. Do one of the following:
    • If you already have a token, insert it in the Log In to GitHub dialog window: Adding GitHub account with token
    • If you want to obtain a new token, click Generate . Enter your GitHub credentials in the browser window that opens. 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. In the token generation page, make sure that the repo , the gist and the read:org scopes are enabled (refer to Understanding scopes). Click Generate token , copy the token, and paste it into the Log In to GitHub dialog window.
  3. Click Log In

Create a new GitHub account

  1. Press Control+Alt+S to open the IDE settings and then select Version Control | GitHub .
  2. Click .
  3. Select Log In via GitHub .
  4. In the browser window that opens, click Create an account and complete the registration process on GitHub.
  5. Return to the PyCharm settings, click Cancel , and then repeat steps 2 and 3.
  6. Click Authorize JetBrains in browser.

Manage multiple GitHub accounts

You can use multiple GitHub accounts in PyCharm: for example, a personal account to work on an open-source project, and a corporate account for your main job.

  1. Press Control+Alt+S to open the IDE settings and then select Version Control | GitHub .
  2. Use the button to add as many accounts as you need.
  3. (Optional) To set an account as a default one for the current project, select it and click . 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.

If you cannot view pull requests in the IDE, or you get an error when you log in to a GitHub account and perform any git operation, refer to the Operations Against a GitHub Repository Are Failing article for troubleshooting tips.

Как в PyCharm из проекта создать репозиторий на GitHub?

Так, чтобы не заходить на сайт GitHub и не прибегать к помощи командной строки.

  • Вопрос задан более трёх лет назад
  • 30067 просмотров

Комментировать

Решения вопроса 1

Vov Vov @balamut108

Создаёте новый проект, активируете VCS (Enable VCS), создаёте новый репозиторий Git, добавляете в него нужные файлы, делаете коммит, далее в VCS выбираете Import Into Version Control -> Share Project in GitHub.
Это будет работать при условии что у Вас корректно настроены VCS в Settings -> Version Control.

Ответ написан более трёх лет назад

Нравится 13 1 комментарий

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

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