Skip to main content

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

  1. Create a branch with the name: [your name]/[what is this about]
    • For other purposes, use . instead of / as delimiter since / means folder
  2. Work on the new branch and push all the commits, periodically pull from master to ensure you have the latest code
  3. Create a merge request and resolve conflicts
  4. Address code comments and get approval
  5. Merge into main
  6. 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