Skip to content

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"
  • 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 with git config --global pull.rebase true
Update current local branch with commits in the main local branch
git merge origin/main
Delete remote tracking branches that were deleted from the remote repository
git remote prune origin
  • Make git pull or git fetch prune by default with git 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> ...
    • Reference: Cleaning up old remote git branches

GitHub-specific best practices