- Clone the Repository:
git clone [repository URL]
- Check Current Branch:
git branch
- Create a New Branch:
This creates a new branch and switches to it.git checkout -b [new-branch-name]
- Add Changes to Stage:
or for all changes:git add [file-name]
git add .
- Commit Changes:
Write a clear, concise commit message explaining your changes.git commit -m "Your commit message"
- Switch to Main Branch:
git checkout main
- Pull Latest Changes:
git pull origin main
- Switch Back to Your Branch:
git checkout [your-branch-name]
- Merge Changes from Main to Your Branch:
git merge main
- Resolve any merge conflicts if they arise.
- Push Branch:
If it's the first push for the branch, Git will provide a command to set the upstream branch.git push origin [your-branch-name]
- Open GitHub Repository in a Browser.
- Navigate to 'Pull Requests' and click 'New Pull Request'.
- Select your branch and the branch you want to merge into (usually main/master).
- Fill in the PR template, providing context about the changes.
- Request reviews from maintainers or team members.
- Make any requested changes on your local branch.
- Commit and push these changes as before. The PR will automatically update.
- Once the PR is approved, it can be merged into the main branch.
- Delete your branch from GitHub if it's no longer needed.
- Optional: Some projects require branches not to be removed for tracking purposes
- Switch to Main Branch:
git checkout main
- Pull Latest Changes:
git pull origin main
- Delete Local Branch (optional):
Only do this if you're sure you won't need the branch anymore.git branch -d [your-branch-name]
- Keep Your Branches Updated: Regularly pull changes from the main branch to avoid large merge conflicts.
- Commit Messages: Write meaningful commit messages to document your changes effectively.
- Handle Merge Conflicts: In case of merge conflicts, carefully resolve them considering the latest code on the main branch.
This cheat sheet covers the typical workflow for contributing to a project on GitHub. Remember, each project may have its own specific guidelines, so it's always good to read the project's CONTRIBUTING.md
file if available. Happy coding! 🚀