Как клонировать репозиторий с github pycharm
Перейти к содержимому

Как клонировать репозиторий с github pycharm

  • автор:

Manage projects hosted on GitHub

You can clone a repository that you want to contribute to directly from PyCharm and create a new project based on it.

From the main menu, choose Git | Clone . If the Git menu is not available, choose VCS | Get from Version Control .

In the Get from Version Control dialog, choose GitHub on the left.

Log in to GitHub by doing one of the following:

If you have a token, click Use token , then paste the token in the Token field, and click Log In .

Otherwise, click Log In via GitHub .

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.

Select a repository from the list of all GitHub projects associated with your account and the organization that your account belongs to.

In the Directory field, enter the path to the folder where your local Git repository will be created.

If you want to create a project based on these sources, click Yes in the confirmation dialog. PyCharm will automatically set Git root mapping to the project root directory.

Share a project on GitHub

You can add a remote GitHub repository for a project you are developing locally, so that others can view it or contribute to it.

Open the project you want to share.

From the main menu, choose Git | GitHub | Share Project on GitHub .

If you have already registered your GitHub account in PyCharm, connection will be established using these credentials.

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

When connection to GitHub has been established, the Share Project on GitHub dialog opens. Specify the new repository name, the name of the remote, and enter a description of your project.

You can select the Private option if you do not want to allow public access to your repository for other GitHub users.

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

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.

Do one of the following:

Select Git | GitHub | Open on GitHub from the main menu.

Select a file in the editor or in the Project view, and choose Open In | GitHub from the context menu.

Select the file in the Project view, press Control+Shift+A , and type Open on Github .

If you are signed in to GitHub, the remote version of the file will open in the browser.

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.

If you are opening the GitHub file version from the editor, the file will be also automatically scrolled to the current line.

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

PyCharm Integration with GitHub

Setting up Version Control for Collaboration Projects

Akshay Sinha

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 ! :).

tcd1558 / PyCharmPython_with_GitHub.md

Here are the steps necessary to setting up a PyCharm Python project with a GitHub Repository. It is not obvious on what to do first: create a PyCharm project and add it to GitHub — or — create a new GitHub repository, clone it and convert it into a PyCharm Python project. Here is the approach I took. This text ist written from the perspective of MacOS.

P.S. PyCharm and IntelliJ are both from JetBrain. No wonder, the look and feel are very simular.

3. Check your Python installalation

It is always a good idea to make sure your installation is current. You do not want to encounter problems, which have already been fixed.
An even better approach is to create a virtual machine with e.g. docker and create your development environment from scratch with each project. In this way, you can also have different environments for different projects at the same time.

3.1 Update python

Is there a new python version?
Go to MD:python.org
HTML: python.org
Double click the download (Chrome browser: at the bottom margin of the browser). From a terminal, you can initiate the installation with the command

Follow the instructions to install python.

3.2 Update Anaconda

Check the version of the current installed conda software.

Update the conda package manager to the latest version. To actually update, you will have to confirm a prompt.

Use conda to update Anaconda to the latest version.

3.3 How to verify what is installed

P.S. When using Anaconda, the python version might be slightly older than the publicly available python version.

Notice: python can install packages with the pip/pip3 command, but python itself can not be updated using the pip/pip3 command.

If there is a newer version of pip available, execute

$ pip3 install —upgrade pip
$ pip install —upgrade pip

Other useful pip commands

$ pip3 list # List installed packages
$ pip3 show pip # Show information about installed packages
$ pip list —outdated # Show packages which have an upgrade at pypi

Update all packages installed with pip/pip3:

There is no dedicated command to get to the most current version. Instead you have to create a requirements list using the freeze option.

Edit requirements.txt, and replace all ‘==’ with ‘>=’. Use the ‘Replace All’ command in the editor. Only lines with ‘==’ are relevant. Lines not containing ‘==’ are irrelevant.

$ cat requirements.txt | grep ‘==’ | sed -e ‘s/==/>=/g’ >requirements2.txt

pip install -r requirements2.txt —upgrade

P.S. If you encouunter problems, edit the requirements2.txt file and revert the ‘>=’ back to ‘==’ and rerun the pip install command.

Alternatively:
Open a new python program in PyCharm. If the package needed through import is missing, hover the mouse over the <pkg> name.

from pkg import function
e.g.
from selenium import webdriver

Hover over the ‘pkg’. From the popup select ‘Install package <pkg>’

3.4 homebrew update

Update the brew package database

Check for outdated packages

3.5 Reboot the system

To make sure, the entire system is using the latest software, it is recommended to reboot your system.

4. Download PyCharm

[Jetbrains/pycharm][https://www.jetbrains.com/pycharm/download]
Community
Download .dmg(Intel)
Install from Chrome Downloads.

4.1 Update PyCharm

In the main bar click on Pycharm.
The select ‘Check for. Updates. ‘

If there is an update available, you will see a notification at the bottom right once you open a project.

5. Create a Python Project in PyCharm

  1. Open PyCharm CE
  2. [New Project]
  3. Change Location:

6. Create a GitHub repository

  1. Go to the GitHub page of the team leader (If it is just you, you are the team leader):
    https://github.com/<team lead>
  2. In the top, black bar click on the + sign
  3. Select ‘New repository’
  4. Match the name with the local project:
  1. Provide a Description
  1. [v] Add a README file
  2. Click [Create repository]
  3. Capture the URL:
    https://github.com/<team lead>/<MyProject>
    Notice: There is a pull down button at the top left with a branch icon. This icon indicates, what name is used for the tree. This used to be ‘master’ and now ‘main’ is being used. Depending on the git version used on your system, there might be a conflict. Below are instructions on how to resolve this conflict.

7. Prepare the Pycharm Python project to connect to GitHub

7.1.1 Via a terminal

/PycharmProjects/<MyProject>
$ git init

7.1.2 Via PyCharm

  1. In the top bar, select the VCS tab.
  2. Enable Version Control Integration.
  3. Select a version control system to associate with the project root: [Git]
  4. [OK]

7.2.1 Via a terminal

When you made a mistake with above link, you can remove it with:

and display your setting with

Check the status of git with

Please check what name is used for the tree. Look for ‘On branch ‘

7.2.2 Via PyCharm

  1. Right click the project
  2. Select ‘Git’
  3. Select ‘Manage Remote. ‘
  4. Click on [+]
  5. Name: origin
  6. URL: https://github.com/<team lead>/<MyProject>.git
  7. [OK]
  8. If you made a mistake with the URL, an error message will pop up and you have a chance to correct your URL
  9. When the Name and URL have been added, click on [OK]

PyCharm does not have an equivalent to the ‘$ git status’. Changes to files are indicated by their color. See File Status Highlights for details on the meaning of the colors.

The branch name can be verified by the name in the bottom right margin, next to a lock. Depending on your git version it is either ‘Y main’ or ‘Y master’

  1. Enter CMD+, or from the top bar, click on PyCharm, Preferences
  2. Version Control
  3. Git
  4. Protected branches: <name>
  1. Right Click Project
  2. Git,
  3. Branches.
  4. Local Branches
  5. <name>

8. Check for branch name conflicts

In GitHub under https://github.com/<team lead>/<MyProject> in the tab <> Code, there is pulldown menu button to the top left of the page. This button indicates what tree you are currently viewing. By default this is the tree ‘main’.

If the local name (e.g. master) and the remote name (e.g. main) do not match, you first have to add something to your local tree so you can give it a new name.

>>>Do not create the change here<<<

The project in GitHub is a GitHub repository and not a PyCharm project. The PyCharm Project is not a GitHub repository. By adding and committing the PyCharm files to the GitHub repository, you have all that is required to synchronize the branch names. The steps needed to synchronize your PyCharm project with the GitHub repository are documented in the next section.

9. Make changes to your local tree

When you enabled your PyCharm Project for GitHub (or # git init), a new .git directory with some configurations files were created. You can now add these files to your local staging area.

PyCharm Version Control and git complete tutorial for beginners

replace "My name" and " [email protected] " with your values which will be associated as git account values.

install git for linux

Adding git to Ubuntu and Linux Mint is really easy just by a single command:

Default installation on Ubuntu 18.04 and Linux Mint 18 is:

PyCharm git operation

All version control operations like:

  • commit
  • pull
  • push
  • remote

are located in main menu — VCS

For example checking for remotes — linked projects with git can be found:

  • VCS
  • Git
  • Remotes

You can change, delete or add you remotes from the open dialog.

If you work with Version Control you will want to show tool bar Version control by:

  • ALT + 9
  • or from menu:
    • View
    • Tool Windows
    • Version Control
    PyCharm git commit

    In order to commit your changes you need to have remove set up.

    • go on view Version Control — ALT + 9
    • Local Changes
    • Select the Changelist — i.e. Default
    • Right click
    • commit — CTRL + K
    • Select what to be commit
      • you can commit everything or select only one / several files
      PyCharm git push

      You can push using the previous section or to push later by using:

      • Menu
      • VCS
      • Git
      • Push — CTRL + SHIFT + K
      Pycharm git clone

      If you want to clone a repository from github.com you can do it by these steps:

      • File
      • New
      • Project from Version Control
      • Git
      • URL — enter the remote URL address
        • for example (Book Think Python) — https://github.com/AllenDowney/ThinkPython.git
        • only if you used it for first time

        By default you will clone the full repository and will set up the master branch. If you want to change the branch you can clone the address of the other branch.

        Pycharm git checkout

        If you want to change the current branch or preview older versions (previous commits) you can do it from

        • go on view Version Control — ALT + 9
        • Log
        • Select Revision
          • you will see all revision with user and dates on left
          • on the right you will see all changes
          Pycharm git pull

          If you need to pull changes from other users using git can be done by:

          • Menu
          • VCS
          • Git
          • Fetch

          This will check the remote repository for any changes. In case you need changes you will see them in the Version Control window — ALT + 9 . You can view the new modifications in tab Log. If you want to pull the changes then you can do it from:

          • Menu
          • VCS
          • Git
          • Pull

          After successful pull request you will see new tab Update Info. There are all changes divided in three different categories:

          • Pull(12 items)
            • Updated from server(12 items)
              • Updated(3)
              • Created(7)
              • Deleted(2)

              PyCharm Version Control

              Version Control window can be shown by ALT + 9 or:

              • Menu
              • View
              • Tools Windows
              • Version Control
              Local Changes

              The first tab is named Local Changes inside you can find all your changes separated in changelists. You can do several operations from this tab:

              • commit change — CTRL + K — Saving your changes in a repository. Git add adds a change in the working directory to the staging area.
              • revert — CTRL + ALT + Z — This will revert (remove, give up) your local changes and will return the older files versions.
              • delete — completely delete the file from this project
              • Move to another changelist — you may want to maintain several different changelist. This is useful in case of project specific files like IDE, DB settings etc
              • ignore — in case that the file is not added to VCS and the remote repository you can ignore files or folders. Several technical folders need to be ignored in order to avoid problems. You can ignore also test directories or big files.

              In this tab you can see all revisions and code changes. You can checkout to another version / branch. Compare with previous versions by selecting a file and pressing CTRL + D . New window will be open with two version of your code.

              Console

              If you want to know what commands are executed or simply check your daily activities related to git. You can visit tab Console. Inside you will find the actual git commands with all parameters. For example:

              Update info

              The last tab Update info will be shown after successful pull. Inside you can find information about all pulled changes:

              • Updated(3)
              • Created(7)
              • Deleted(2)

              Show git information

              How to check the current user name or email:

              To list everything in the git file:

              Setup proxy and Git

              Setup by command

              The easiest way too add proxy to your git configuration is by:

              • proxyuser — proxy user ( you can check the proxy configuration Windows 10 — Settings/Network & Internet/Proxy or ubuntu — System/Preferences/Network Proxy)
              • proxypwd — proxy password
              • proxy.server.com — proxy server
              • 8080 — proxy port

              Disable git proxy by

              Setup by file

              If the command line is not your favorite way of working, you can just edit .gitconfig

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

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