my-git

Branch and Merge

English 中文

Branches are used to isolate tasks, and merging is used to bring validated changes back to the main line.

Good branching habits can reduce conflicts, minimize unrelated changes, and make PRs easier to review.

When to Create a Branch

Create a branch for each independent task:

Create a branch:

git switch -c feat/my-task

Switch back to the main branch:

git switch main

Branch Naming Suggestions

feat/github-governance-guide
fix/recover-lost-commit-example
docs/ai-native-git-workflow
hotfix/remove-broken-link
ai/review-large-repo-guide

For more templates, see Branch Naming Convention.

Pre-Merge Checks

Before merging, first check:

git status
git diff --stat main...HEAD
git log --oneline main..HEAD

Confirm that:

Merge Methods

merge commit

Retains the branch integration history, suitable for teams that need to audit the merge context.

git switch main
git merge --no-ff feat/my-task

squash merge

Squashes multiple commits in a PR into a single commit, suitable for keeping the main branch history clean.

rebase merge

Reapplies the commits in the PR on top of the target branch, suitable for teams pursuing a linear history.

The merge strategy should be unified according to team conventions, rather than chosen based on personal preference.

Further Reading