GitHub Contributions
Collaborating on GitHub is more than just pushing code. It involves a structured workflow of Forking, Branching, and Pull Requests (PRs). This ensures that code is reviewed and tested before being integrated into the main project.
🍴 The Fork & Pull Request Workflow
This is the industry standard for contributing to open-source and private team projects where you don't have direct "write" access to the main repository.
Step 1: Forking
Click the Fork button on the top-right of the original repository. This creates a personal copy of the project under your GitHub account.
Step 2: Cloning
Clone your fork to your local machine:
git clone https://github.com/your-username/project-name.gitStep 3: Branching
Always create a new branch for your specific change. Never work directly on main.
git switch -c feature-nameStep 4: Pushing
Push your local branch to your fork on GitHub:
git push origin feature-nameStep 5: Opening a Pull Request
Navigate back to the original repository on GitHub. You will see a "Compare & pull request" button. Add a clear title, describe your changes, and submit!
🔄 Syncing with Upstream
As the original project moves forward, your fork will become outdated. You must sync it to avoid conflicts.
1. Add the "Upstream" Remote
Point your local repo to the original source:
git remote add upstream https://github.com/original-owner/project-name.git2. Fetch & Merge
Download the latest changes and merge them into your local main:
git fetch upstream
git switch main
git merge upstream/main📜 Pull Request Best Practices
- Atomic Fixes: Keep your PRs focused. Fix one bug or add one feature at a time.
- Detailed Descriptions: Explain why you made the change, not just what.
- Resolve Reviews: If a maintainer requests changes, make them in your local branch and push again. The PR will update automatically.
- Check Guidelines: Always read the project's
CONTRIBUTING.mdfile for specific rules (e.g., commit message formats).
[!TIP] Signed-off-by Some projects require you to certify the "Developer Certificate of Origin." You can do this automatically by adding the
-sflag to your commits:git commit -s -m "message".