Contributing to a Git Repository¶
For a walkthrough of the contribution process, read First Contributions.
Comments on the First Contributions walkthrough
- If you have access to the repository, there is no need to fork it; clone and work on the repository itself
Goals¶
- Main branch only contains working code
- Collaborate with others effectively (i.e., code reviews)
- Clear, progressive development process
Issues¶
- Bug: Describe issue, steps to reproduce, expected behavior, screenshots, additional context
- Feature: Give context, describe solution, describe alternatives, additional context
- Link to relevant code, projects, labels, milestones, etc.
Commits¶
- Make a commit for each unit change, giving it a descriptive name
- For example: "added
<function_name>
function", "updated tests to match"
- For example: "added
- At the end of a session
git push
, to update the remote repository with your changes
Pull requests¶
Compared to committing directly to the main branch, pull requests can be used to ensure that the code in the main branch is clear and correct through:
- Continuous integration: automated linting and testing
- Code reviews: getting someone to read over and test your code
Creating a pull request:
- Describe changes, expected behavior, and how to verify
- Link pull request to the issue it resolves: linking a pull request to an issue
- Can create as a draft if incomplete, which disables merging
- New commits to the branch will be automatically added to the pull request
- Add reviewers to test the pull request
- Once the pull request is ready to merge into the main branch, I recommend the "Squash and Merge" merge method to keep the main branch commit history clear and concise,
or "Rebase and Merge" for hotfixes and one off commits
- Learn more about GitHub merge types and best practices here
Updating your local repository¶
Update the current local branch and the remote tracking branches for all other branches
git pull --rebase
- Why use
--rebase
? - Make
git pull
rebase by default withgit config --global pull.rebase true
- Make
git pull
orgit fetch
prune by default withgit config --global fetch.prune true
- Local branches tracking a remote that has been prunes are identified as gone in the output of
git branch -vv
- Delete these branches with
git branch -D <branch1> <branch2> ...
- Delete these branches with
- Reference: Cleaning up old remote git branches
- Local branches tracking a remote that has been prunes are identified as gone in the output of
GitHub-specific best practices¶
- Labels: GitHub labels best practices
- Milestones and projects: Milestones vs. projects
- Releases: Releasing Projects on GitHub
- Discussions: gather feedback and ideas from non-code collaborators
- Actions: automate, customize, and execute software development workflows
- Wiki: host very basic documentation, GitHub Flavored Markdown only
- Choosing the right open source license