Git On Pycharm - WheatonCS/Lexos GitHub Wiki

This guide explains how to use Git while working on Pycharm.

Warning: This is not a tutorial on Git, this will just show you how to use Git while using PyCharm.

Workflow

The following demonstrates the the process of using Git from PyCharm.

Creating a New Feature or Fixing a Bug in the Code

Create an issue

The issue needs to have a readable and detailed description of:

  • The problem or feature
  • The proposed way to solve the problem or the proposed implementation

You don't have to finish writing the issue all at once.

But you do need to finish the proposal before moving on to the code. Here is the reason:

  • Everyone can read your issue, but very few people can read your mind.
  • People can make suggestions on your issue to help you implement the feature.
  • People can also make suggestions when your proposal conflicts with other's work.
  • It is always good to make a plan first.

Create a new branch

See: Branch.

  • The branch you create needs to start with feature/ or bugfix/ so it is understandable to the other users and the Admin
  • The branch needs to end with the issue number you need (Find your issue at: Issues)

Here is an example branch name: feature/matrix_ajax#494

While working on a branch

Always:

When you are finished

See: PR

Just provide brief description and then wait for the Admin to review your request!

Viewing and Editing Other Users Branch

Checkout the remote branch

see: Checkout

And then you can work on the branch

Again, don't forget to:

When you are finished on their branch

You can create a pull request for this branch, or wait for the branch-creator to create the pull request

See PR

Git Operation

The following is an image tutorial on basic Git operations on Pycharm

Commit

You can commit your code by clicking the green up button oin the top right corner of Pycharm IDE, or use Ctrl+K.

Pycharm will then display this window:

Before you commit:

  • Check the optimize import and perform code analysis on the right.
  • Write clear commit message.
  • The first line of the commit message is a summary of the commit, do not use more than 50 characters on the first line.
  • Only select the file you need to change.
  • Commit as often as possible.

After you finish your commit:

  • If you have internet access, you can commit and push at the same time by mousing over the commit button on the bottom left corner of the window and selecting Commit and Push:
  • If you only want to commit, you can click the Commit button on the bottom left corner of the window:

Push

NOTE: The push operation requires internet access.

In Pycharm you can open the Push window via Ctrl+Shift+K

You will see all the commit messages on the left, and all the changed files on the right.

Just click the Push button on the bottom right corner of the window to push.

Warning: If you want to force push (you probably shouldn't), check with the Admin first!

Merge

While you are working on your branch, you want to always keep up with the work of others. This requires the branch you are working on to be up to date with master branch.

It is recommended to merge as much as possible, you should merge after every push.

To merge the code from the master branch to your branch, you need to:

  1. Click the Git on the bottom right corner of the status bar.
  2. Click the origin/master branch under Local Branches, Not the master under Remote Branches.
  3. Click Merge.

If this does not work you may have to do a manual merge, see the next section for more details.

Manual Merge

Sometimes when you push (pull) or merge, you will encounter a Merge Conflict, which requires you to do a manual merge:

Select your file and then click the Merge... button:

  • The brown line indicates conflicts.
  • On the right is your file.
  • On the left is another user's file.
  • In the middle is the merge result

You can click the little >> or × next to the file to accept or reject the changes. (Or you can click either the Accept Left or the Accept Right button in the bottom left corner of the screen to accept the other user's file or to accept your file)

In this case I accepted (>>) my change and rejected (×) the other user's changes.

Now just click the Apply button in the bottom right corner to finish merging your current file with the master branch.

Create a Branch

  1. Click the Git button on the bottom right corner of status bar.
  2. Click the New Branch button at the top of the window that appears.
  3. Give your branch a branch name.
  4. Now you are in your new branch!

Checkout a Branch

  1. Click the Git button on the bottom right corner of status bar.
  2. Click the branch you want to checkout (in this case the local master).
  3. Click the Checkout button
  4. You are now in the branch you selected to checkout.

Pull Request to Master

  1. Merge origin/master into current branch, see Merge
  2. Press Ctrl+Shift+A and then search for pull request.
  3. Fill in the description and title. Make sure the Base branch is master
  4. Select the Ok button in the bottom left corner of the screen
⚠️ **GitHub.com Fallback** ⚠️