-
Notifications
You must be signed in to change notification settings - Fork 0
7. Git best practices
While no productivity system is perfect, especially in team efforts, there are several best practices that can facilitate fast code deployment. After reading other people's systems and beta-testing each one, I am now offering my own set of best practices that I hope will help you with your future software development and collaborations.
The default branch you start off with when initially tracking your folder using Git is master
. It is common to reserve the master
branch for the finished software product while developing code on other branches. Each branch can be made for a specific task, however I do recommend 5 branches to make every time you start a repo:
a) A username branch (ie scampit
for yours truly)
* I typically start working with the code in this branch, and then create new branches if the task I'm working on needs significant development time.
b) A feature branch (ie make_website_sliderbar
)
c) An issue branch (ie fix_X_bug
)
d) A dev
branch for pre-production
e) A version
branch for specific version your code may exist in.
I have found that making commits after finishing even the smallest tasks and pushing those changes in a pre-production branch helps a) keeping track of what you're working on, especially if you look at your commit history, and b) saves A LOT of time if you f****d up.
Excellent commit messages can save a ton of time and can help other team members follow your work seamlessly. My suggestions for writing commits:
a) For short (and simple) commits, it is only acceptable to use git commit -m "message"
if you can write a summary of your changes in less than 7-10 words. Otherwise, write a full commit message using git commit
.
b) Keep your subject line less than 7-10 words summarizing what your changes are. If you can't do that, you need to commit more.
c) Separate the subject line from the body with a new line.
d) In the body of the commit message, explain what you have done and why you have implemented a change in the code.
In projects with collaborators, I always set branch rules to enforce a code review in a Pull Request before merging changes to master
. This is because I want the best code to go to production, and having multiple sets of eyes to review the code and offer suggestions is invaluable in catching your mistakes. Also, I found that it is a good learning experience for more novice coders to look at code, and critically evaluate it from a reviewer's standpoint. If it's possible, I'd suggest having someone review your work at the end of every workday, and reviewing other people's code frequently, even if it's not ready for production.
Contributions are welcome! To contribute to this guide, please submit a pull request with a detailed description of:
- Which specific section you added or changed
- What you specifically added
- How does your contribution this make the tutorial better
Happy gitting!