Git best practices
Feature Branches
- Develop: for daily development
- Staging: for staging
- Master: for production
Initialize
Fork
Fork from upstream to create my own repo
Download from online repo
git clone [url]
Initialize in untracked folder
git init
git remote add origin [origin url]
git add .
git commit -m "Initial commit"
git push -u origin master
Contributing
- Create a branch with the name:
[your name]/[what is this about]
- For other purposes, use
.
instead of/
as delimiter since/
means folder
- For other purposes, use
- Work on the new branch and push all the commits, periodically pull from master to ensure you have the latest code
- Create a merge request and resolve conflicts
- Address code comments and get approval
- Merge into main
- Close obsolete branches
See https://www.atlassian.com/git/tutorials/comparing-workflows/feature-branch-workflow
Commit message
DCO signoff
Sign-off is a requirement for getting patches into the Linux kernel and a few other projects, but most projects don't actually use it. It was introduced in the wake of the SCO lawsuit
git commit --signoff
To signoff manually, add the following to commit message
Signed-off-by: [Name] <[[email protected]]>
Why merge features branches instead of rebase
- merge
- simple
- less likely to create issues
- rebase
- basically changing commit history
- resolving conflicts commit by commit, rather than resolving as a whole branch
- likely to create conflicts