Prepares pull request branches by stashing changes, creating feature branch from main, reviewing changes, running code quality checks on modified files only, generating conventional commit messages,...
Complete workflow for preparing PR branches: stash changes, create branch, review changes, run quality checks, commit, and push.
Important: Always pull latest main branch code before creating new branch.
git status # Confirm uncommitted changes exist
git stash push -m "temp: stash before creating branch"
git checkout main
git pull origin main # Pull latest code from main branch (use actual main branch name if different, e.g., master)
git checkout -b <branch-name>
git stash pop
Branch naming: Infer from changes if not specified. Use prefixes: feat/, fix/, refactor/, docs/, style/, test/, chore/.
git diff
git diff --name-only # Get modified files list
Check for unnecessary modifications:
Only on modified files - never format entire project.
Detect tools from project config:
package.json scripts, .eslintrc*, eslint.config.*, .prettierrc*pyproject.toml, .ruff.toml, .flake8, .pylintrc, requirements.txtRun checks on modified files only:
# Example: JS/TS
npx eslint <modified-file>
npx prettier --check <modified-file>
# Example: Python
ruff check <modified-file>
black --check <modified-file>
Handle results:
Critical: Only run checks configured in project. Never modify files user didn't change.
git log --oneline -10 # Detect commit language from history
Language detection:
Conventional Commits format:
<type>(<scope>)[!]: <subject>
<body>
Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
Breaking changes: Add ! after type(scope): <type>(<scope>)!
Guidelines:
Examples:
Chinese:
feat(ui): 添加按钮组件
- 新增 ButtonPart 类型支持
- 实现 part-button 组件
English:
feat(ui): add button component
- Add ButtonPart type support
- Implement part-button component
Breaking change example:
feat(auth)!: change login method
Login now requires token instead of password
git add .
git commit -m "<commit-message>"
git push -u origin <branch-name>
Critical: Never use --force or -f flag when pushing. If push fails due to conflicts, pull and rebase/merge instead.
Scenario: Adding a new button component
# 1. Stash and create branch
git stash push -m "temp: stash before creating branch"
git checkout main && git pull origin main
git checkout -b feat/add-button-component
git stash pop
# 2. Review changes
git diff
git diff --name-only # Output: src/components/Button.tsx
# 3. Run checks on modified files only
npx eslint src/components/Button.tsx
npx prettier --check src/components/Button.tsx
# 4. Generate commit (detected Chinese from git log)
git log --oneline -10
git add .
git commit -m "feat(ui): 添加按钮组件
- 新增 ButtonPart 类型支持
- 实现 part-button 组件"
# 5. Push
git push -u origin feat/add-button-component
main, fallback to master if needed. Always pull latest code before creating new branchgit push --force or git push -f. If push fails, pull and rebase/merge instead