There are a lot of ways to use git to collaborate with other developers. I’ve found the following principles to be useful for keeping my sanity when working with git. My experience has mostly been with small teams of two to six developers, but these principles may apply to any size team.
Of course, “best practices” are elusive, and the following is just my established method.
- Do not commit vendor code.
- Do not commit compiled code.
- Do not commit commented-out code — just delete it.
- Make small commits.
- Explain the why, not the what, in your commit message.
- Create a new branch for every task / small feature / bug fix.
- Rebase instead of merge to resolve conflicts.
- Use pull requests. Get reviews.
- Do not commit or push directly to the master branch.
- Deploy from the master branch to staging.