element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Open Source Hardware
  • Technologies
  • More
Open Source Hardware
Blog GitHub for Beginners: Working with PyCharm and other JetBrains IDEs
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Open Source Hardware to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: shabaz
  • Date Created: 24 Jun 2023 10:18 PM Date Created
  • Views 3477 views
  • Likes 11 likes
  • Comments 3 comments
  • github
  • open source
Related
Recommended

GitHub for Beginners: Working with PyCharm and other JetBrains IDEs

shabaz
shabaz
24 Jun 2023
GitHub for Beginners: Working with PyCharm and other JetBrains IDEs

Table of Contents

  • Introduction
  • Cloning a Repository
  • Creating a Branch and Publishing the Branch
  • Editing Code and Committing your Code
  • Creating a Pull Request
  • Merging the Code to the main branch
  • Creating your Next Feature
  • Viewing Branches Graphically
  • Summary


Introduction

If you’ve read the previous blog post, you’ll be familiar with what GitHub is all about, and how to use it with Visual Code, which is convenient for working with software written in any language.

A key point is that GitHub allows you to store your code in repositories, one per project, and you or others can incrementally add new functionality, or fix code bugs, in different revisions that can always be revisited in case a problem occurs, and therefore it becomes quicker to fix problems that might be introduced as the code becomes more complex over time, as more and more lines of code is added to your project. As code is written, it can be periodically labeled (in an operation known as a commit) so that you can keep track of what has been added. The entire history of commits in a sequence is known as a code branch.

A nice way of working is to create a separate branch of code whenever you wish to add a new feature, commit code on that branch as you develop it, and merge it into the main branch once the feature is complete, reviewed, and tested. This blog post shows how to do exactly that. It covers just that scenario since that is likely to be the most useful one for newcomers to GitHub.

If you’re completely new to GitHub, then it is suggested to at least read the first part of the earlier blog post, which explains how to understand the following diagram. The diagram is near-identical to the previous blog diagram. Otherwise, no other background knowledge is required, to make sense of this blog.

image

The diagram above shows what will be covered in this blog (assuming that an initial code repository is already created, perhaps containing some code), and the diagram is interpreted from left to right, and you may wish to open it up in a separate window while following along with the rest of the content.

The screenshots in this blog are taken from PyCharm, but they will be near-identical regardless of whichever JetBrains Interactive Development Environment (IDE) product is used (such as CLion).

Cloning a Repository

At startup, in the Welcome to PyCharm window, click on Get from VCS (Version Control System):

image

If you wish to work on your own code, select GitHub and then log in; a browser window will open up for entering your GitHub credentials:

image

Select your project repository, and then confirm that the destination (local) directory folder on your PC is fine, and click clone. In the example screenshot below, the GitHub repository is called LD2410, and the destination path is C:\development\my_repos\LD2410

image

PyCharm will download the code into the local folder C:\development\my_repos\LD2410 and PyCharm will launch into its main layout, which can be examined. All the key areas that will be used in this blog post are highlighted in the screenshot below.

image

Note: If you can't see the branch name displayed at the lower-right, then you may need to go to View->Appearance->Status Bar Widgets and then ensure that Git Branch is checked.

Creating a Branch and Publishing the Branch

If you wish to develop a new feature, the first thing you’ll want to do is to create a new branch for it.

Use the Git menu to select New Branch:

image

You’ll be prompted for a new branch name. Ensure that the Checkout branch box is checked, as shown in the example screenshot below. In the example, the new branch is called implement_formatting:

image

The lower-left corner will show a popup speech bubble indicating success:

image

You can open up the Git lower window if you like, to see that the new branch has been created. Ensure that the new branch is indicated at the lower-right corner of PyCharm.

image

Now any code changes you make in the project folder (C:\development\my_repos\LD2410 in this example) will occur for the new branch. This is just a local folder, so at some stage you will wish to update the cloud repository with the same branch information. You can do that by clicking on the Push icon in the Git toolbar at the top-right:

image

A pop-up window will appear; click on Push:

image

A pop-up notification at the lower-right will show success:

image

Now anyone can see that you’ve created the branch, in the online GitHub repository:

image

Editing Code and Committing your Code

PyCharm is excellent for editing code and testing code. As you reach key points in the development of your code, you can periodically checkpoint your code locally with text descriptions, so that you can always revert back in case you need to. The checkpointing procedure is more formally known as a commit operation. This is done by either clicking on the Commit button in the Git toolbar, or selecting the Commit pane from the left side:

image

Type a commit description, and then press the Commit button:

image

Note that all these commits are in the local folder, and not in the cloud. When you’re happy to do so, transfer the commits to the cloud, by using the Push icon as before:

image

The pop-up window will indicate the feature branch name, and underneath that, it will indicate all the commit operations. In the example screenshot below, three commits were done, and they all need to be sent to the cloud. On the right side, you can see the affected files where the code changes were made. Ensure that the branch name is selected on the left, and then click on Push:

image

Now anyone looking at your branch on GitHub can see the changes:

image

Once all the coding is complete and tested, you may wish the code to be merged into the main branch. The way to do that is to first create a Pull Request, to advertise the fact that you wish your code to be reviewed and merged. That is discussed next.

Creating a Pull Request

The Pull Request will send a message that you wish your code on the feature branch in GitHub to be code-reviewed and eventually merged into the main code. Select Git->GitHub->Create Pull Request from the PyCharm menu bar.

image

The Create Pull Request pane will appear on the left side, all ready for you to type in comments and click on Create Pull Request:

image

The Pull Request is now visible in the GitHub repository:

image

Now the code owner can inspect it, examine your code changes, and perform the merge. My example has a typo as can be seen in the screenshot above!

If you own the code repository, then you can perform the merge operation yourself, although a code review is recommended.

Merging the Code to the main branch

By this point, the feature development is complete, the feature has been tested, and a Pull Request has been created, and the code has been reviewed. The code is ready to be merged into the main branch.

If you have just performed the Pull Request, then a Merge button will already be visible, so that can be clicked to perform the merge operation.

image

Otherwise, from the PyCharm menu bar, select Git->GitHub->View Pull Requests. You should either see the request as shown in the screenshot below, or you may see the text “No pull request matching filters. Clear filters”. If you see that text simply click in the search box (the box with a magnifier) and hit Enter. That should clear the filter and allow the request to be visible as shown in the screenshot:

image

Double-click the request, and you should see the following display. Click on Merge and confirm on any pop-up window.

image

The merge is complete! Now the main branch on GitHub contains your feature branch content.

Creating your Next Feature

You’re now ready to update your local copy of the main branch, and then create a brand new feature branch.

At the lower-right corner of PyCharm, click on the old feature branch name, and select main and then Checkout:

image

A pop-up message will indicate that the project’s local folder branch has been changed. The code in the project folder now contains the original old main branch content.

image

You can update the local folder to contain the latest main branch content from GitHub, by clicking on Update Project from the Git toolbar:

image

Click on OK in the Update Project pop-up window:

image

In the background, a Fetch and Merge operation is actually being performed. Now the main code in your local folder contains the same content as the latest main code on GitHub.

To develop a new feature, create a new branch as before.

Viewing Branches Graphically

Sometimes it can be useful to see the branches in a graphical view. Open up the lower Git window and the Log tab will show the branches on the right.

image

If desired, operations can be performed from the graphical view. For instance, if you wished the code to be switched to an earlier version, you could right-click on that version and select Reset Current Branch to Here.

Summary

PyCharm makes it very easy to add new features to code residing in GitHub. At startup, a VCS (Version Control System) project can be selected, to download (clone) the code into any destination local folder on the PC.

The Git menu can be used to create a new branch for the feature. Code can be committed locally, and then pushed to the cloud using the Commit and Push icons from the PyCharm Git toolbar.

The Git menu can be used to create a Pull Request, allowing others to review your code. The final Merge operation, to get the feature branch content into the main branch can be performed directly from PyCharm too if desired.

Thanks for reading!

  • Sign in to reply
  • dougw
    dougw over 2 years ago

    Great post.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 2 years ago in reply to mp2100

    Hi!

    Good question. There are more than a dozen IDEs in the JetBrains series, one per programming language:

    image

    However, they all have identical look-and-feel, so I used PyCharm as an example, because the same information in this blog will work with any of them. So, for example, if you're doing (say) C/C++ programming then you could use CLion as the IDE, and the same information in this blog will apply. It will almost all apply to Android Studio too, even though that is not on the list in the screenshot above.

    VSCode is excellent and I use it regularly, but I also use the JetBrains IDEs because they are pretty amazing too. I mostly use CLion and PyCharm, but have used a couple of others in the Jetbrains series.

    Whichever language you're programming it, it could be worth trying out the JetBrains IDE for that language if you get a chance. For instance, for working with Pi Pico, I don't use Visual Code, because it is a smoother all-GUI experience with CLion (documented here:  Using CLion for Easier Coding with Pi Pico and C/C++ ) whereas with Visual Code the Ctrl-Shift-P gets used all the time, or tasks have to be set up, and there's extension overload (but that is also the way to get the power of VS Code). In contrast I think I have just one or two plugins installed in CLion.

    The code navigation capabilities are probably nicer in the JetBrains IDEs than in Visual Code, although VS Code is better in other respects too.

     With this blog post, together with the VS Code one, that means most of the popular IDEs are covered for most of the popular languages. I have not done a similar blog with Eclipse, simply because I don't use that often enough (except the customized Eclipses used for microcontroller IDEs) to write about it.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mp2100
    mp2100 over 2 years ago

    Hi Shabaz.  Thanks for posting these instructions.  Because this is “for beginners”, I have a question, questions.  Your first post was for VSCode. I have that.   Here you’ve suddenly switched to PyCharm.  (I had to read the link you provided to know what that was).  Why the switch?  What if I’m not using Python?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube