Pull Request process
Overview of Pull Request Process
Pull Request (PR) is a core mechanism in Git collaborative development, primarily used for code review and feature merging. Developers submit change requests to target branches through PRs, and team members can discuss modifications before deciding whether to merge. This workflow has become standard practice on platforms like GitHub and GitLab.
Preparation Before Creating a Pull Request
The following preparations are required before initiating a PR:
-
Fork the Repository (for open-source project collaboration):
# Click the Fork button on the GitHub interface git clone https://github.com/your-username/repository.git cd repository git remote add upstream https://github.com/original/repository.git
-
Create a Feature Branch:
git checkout -b feature/new-login-form
-
Make Atomic Changes:
// Example: Login form component modification // src/components/LoginForm.js const LoginForm = () => { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); return ( <form> <input type="email" value={email} onChange={(e) => setEmail(e.target.value)} aria-label="Email address" /> {/* Password input... */} </form> ); }
Use clear commit messages:
git commit -m "feat: add accessible email input to login form"
Initiating a Pull Request
-
Push the Branch to Remote:
git push origin feature/new-login-form
-
Operations on GitHub Interface:
- Navigate to the "Pull requests" tab of the repository
- Click the "New pull request" button
- Select the correct base branch (usually main/master) and compare branch
-
Fill in the PR Template:
## Description of Changes - Added accessible email input field - Fixed tab order issue in password field ## Related Issue Fixes #123 ## Testing Steps 1. Go to the login page 2. Verify the email input is recognizable by screen readers 3. Test focus order using the Tab key
PR Review Phase
-
Automated Checks:
- CI/CD pipeline runs tests
- Tools like Codecov check test coverage
# Example GitHub Actions configuration name: CI on: [pull_request] jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - run: npm install && npm test
-
Reviewer Actions:
- Inline comments on specific code
// Suggested change: Add input length limit <input maxLength={320} // Maximum email length /* Other attributes */ />
- Request changes
- Approve
-
Author Handles Feedback:
- Continue committing to the original branch
git add src/components/LoginForm.js git commit -m "fix: add maxLength to email input" git push origin feature/new-login-form
Resolving Merge Conflicts
Conflicts may arise when the target branch is updated:
-
Sync Upstream Changes:
git fetch upstream main git merge upstream/main # Or use rebase git rebase upstream/main
-
Manually Resolve Conflicts:
<<<<<<< HEAD const MAX_EMAIL_LENGTH = 320; ======= const MAX_EMAIL_LENGTH = 254; // RFC standard >>>>>>> upstream/main
After fixing:
const MAX_EMAIL_LENGTH = 254; // Adopt RFC standard
Advanced PR Strategies
-
Draft PR (Work-in-Progress mode):
# Create draft PR using GitHub CLI gh pr create --draft --title "WIP: new login form" --body "Initial implementation"
-
Commit History Organization:
# Interactive rebase to organize commit history git rebase -i HEAD~3 # Squash multiple commits into one
-
Branch Protection Rules:
- Require approvals (at least 2)
- Require status checks (must pass CI)
- Require linear history (no merge commits)
Post-PR Merge Operations
-
Clean Up Branches:
git checkout main git branch -d feature/new-login-form git push origin --delete feature/new-login-form
-
Sync Forked Repository:
git fetch upstream git merge upstream/main git push origin main
-
Version Tagging:
git tag -a v1.2.0 -m "Release login form updates" git push origin v1.2.0
Enterprise-Level PR Practices
-
Link to Project Management Tools:
### JIRA Reference [PROJ-123] Login form accessibility
-
Mandatory Checks:
- SonarQube quality gates
- Security scans (e.g., Snyk)
# Example security scan npm audit snyk test
-
Large PR Splitting Strategy:
graph TD A[Architecture Adjustment] --> B[API Module] A --> C[Frontend Components] B --> D[User Service PR] C --> E[Login Page PR]
Mobile PR Special Considerations
-
Build Artifact Checks:
# React Native example cd ios && pod install npx react-native run-ios --simulator="iPhone 13"
-
Multi-Platform Compatibility:
// Platform-specific code markers if (Platform.OS === 'android') { // Android-specific logic }
-
App Size Monitoring:
# Check APK/IPA size changes du -h android/app/build/outputs/apk/release/app-release.apk
本站部分内容来自互联网,一切版权均归源网站或源作者所有。
如果侵犯了你的权益请来信告知我们删除。邮箱:cc@cccx.cn
上一篇:Fork工作流介绍