While Git and GitHub do most of the heavy-lifting needed to enable effective collaboration, over time we have developed some best practices to keep us all in sync, and to make the best of these powerful tools. New developers learn these from their teammates, and shortly become effective contributors and reviewers.
Here's a list of DOs and DONTs we've been following, which we believe could be helpful for other teams, large are small alike:
Git:
- No commits to master - code is committed only into short-lived feature branches, later merged into master via Pull Requests (PRs) - there's no other way for code to enter the mainline. We even enforce this using GitHub's Protected Branches feature
- Give your branches meaningful names, like everything else you name, really
- Use rebase to update your local master: you shouldn’t have conflicts - you didn’t commit anything directly to master because you followed tip #1, right?
- Use rebase to update a feature branch with changes from master: unless there are other committers working on that branch right now, rebasing (and thus "rewriting history") creates a "fresh start" as if your feature branch included these updates in the first place
- Squash commits before merging to master: again, unless other committers are still working on the same branch, squashing makes the history more concise and readable
Pull Requests:
- Do not merge your own PRs: every PR is reviewed and merged by peers, do not merge your own and and do not merge others' without reviewing
- Feel free to comment on your own PRs if you'd like to point something out to your reviewer. For example, comment on a specific line you've changed if it's unclear why you had to change it
- @Mention users if you want their opinion, it works!
- Delete branch after merging a Pull Request: it’s the same button, you’ll see it
Code Reviews:
- Review everything: we're strong believers in code review as a means of quality assurance, standardization and knowledge sharing, so much so that we've created a nice little tool to "gamify" the process: developers get points for reviewing PRs, and top reviewers are celebrated. Here's how this looks for GitHub's own open-sourced repositories:
- Elaborate: be clear, explain your reasoning, give examples - these are harder to misunderstand and easier to agree upon
- Use common terminology - this will help turning "opinions" into familiar idioms
- Give positive feedback too when reviewing code - not just because it feels good, because it shines a light on the good ideas
- Write down the conclusion even if you reached it offline: we often turn to a year-old Pull Request's discussion page to understand why the code looks the way it does. Make sure your discussions, like your code, are readable to potential future developers trying to follow your reasoning
Got your own best practices? Share them in the comments below, we'd love to learn!
No comments:
Post a Comment