PyCharm Version Control Integration
PyCharm provides complete Git/GitHub integration, allowing developers to perform version control operations directly within the IDE.
Configure Git/GitHub
-
Open
文件/PyCharm → 设置 → 版本控制 → Git -
In 'Git executable path', confirm that PyCharm has automatically detected Git
-
Click Testing Click the button to verify that Git is available

Configure user information
Run in the terminal:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
Integrate GitHub
** 1. Add a GitHub account:**
-
文件/PyCharm → 设置 → 版本控制 → GitHub -
Click + Add account
-
Select a login method:
-
Log in via GitHub: Log in by authorizing through the browser
-
Log in via token: Use a personal access token
Log in via GitHub: Log in by authorizing through the browser
-Log in via token: Use a personal access token

** 2. SSH configuration (optional):**
-
Generate an SSH key:
ssh-keygen -t ed25519 -C "your_email@example.com" -
Add the public key to the SSH keys settings of your GitHub account
Basic operations
We can create a Git repository using the version control button on the toolbar:

Afterwards, the version control button on the project changes to master (main branch):

Commit and push
Commit code
in Commit tool window(Commit Tool Window):
-
Check the files to commit
-
Enter a commit message
-
Select an action:
-
Submit(Commit): Commit locally only
-
Commit and push(Commit and Push): Push to remote immediately after committing
Submit(Commit): Commit locally only
-Commit and push(Commit and Push): Push to remote immediately after committing

Keyboard shortcut:
-
Commit:
Ctrl+K(Win/Linux) /⌘K(Mac) -
Push:
Ctrl+Shift+K(Win/Linux) /⌘⇧K(Mac)
View changes
File status color markers:
-
Blue: Modified
-
Green: Added
-
gray: Untracked
-
Red: Conflict

Pull and merge
Pull the latest code
-
Git → PullorCtrl+T(Win/Linux) /⌘T(Mac) -
Select a merge strategy:
Merge: Keep all commit history
Rebase: Linear history
Merge: Keep all commit history
-Rebase: Linear history
Merge branches
-
Git → 分支 → 合并分支 -
Select the target branch to merge
-
Resolve possible conflicts (see section 6.3)
View history and differences
View commit history
-
Git → 显示历史orAlt+9 -
Function:
View file/project history
Compare different versions
Roll back to a specific version
View file/project history
-Compare different versions
-Roll back to a specific version
Compare differences
-
File difference:
Right-click the file -> Git → 比较与当前分支
or Ctrl+D (Win/Linux) / ⌘D (Mac)
Right-click the file -> Git → 比较与当前分支
or Ctrl+D (Win/Linux) / ⌘D (Mac)
-
Inline difference:
Modified lines show colored markers
Click a marker to view the specific changes
Modified lines show colored markers
-Click a marker to view the specific changes
6.3 Resolve conflicts
1. Conflict scenarios
-
Multiple people modify the same area of the same file
-
A conflict occurs when merging branches
-
A conflict is prompted when pulling code
2. Resolution steps
Open the merge tool
-
The merge dialog pops up automatically when a conflict occurs
-
Or open it manually:
Git → 解决冲突
Three-pane comparison interface
-
Left pane: Your version (current branch)
-
Right pane: Their version (merged branch)
-
In between: Merge result editor
Resolve conflicts
-
Click >> Accept left-side changes
-
Click << Accept right-side changes
-
Manually edit the middle area to merge content
Mark as resolved
-
After finishing editing, click Apply
-
Right-click the file ->
Git → 标记冲突为已解决
Commit the merge result
-
Commit the resolved files
3. Advanced conflict resolution
Use an external merge tool
-
Configure in settings
文件 → 设置 → 版本控制 → Git → 合并工具
Accept a whole version entirely
-
Right-click the file ->
Git → 接受他们的or接受我们的
Practical tips
Partial commit
-
In the commit window, you can:
-
Select specific changes of a file to commit
-
Right-click a code block ->
提交选定行
Select specific changes of a file to commit
-Right-click a code block -> 提交选定行
Stash changes
-
Temporarily save unfinished modifications:
-
Git → 储藏 -
Restore:
Git → 取消储藏
Git → 储藏
Restore:Git → 取消储藏
Interactive rebase
-
Git → 交互式变基 -
You can:
-
Reorder commits
-
Squash commits
-
Modify commit messages
Reorder commits
-Squash commits
-Modify commit messages