Git Best Practice
Rules ΒΆ
Fork the repository and develop based on your own fork - [Mandatory] ΒΆ
Multiple people create branches and work on the same repository makes chaos, whereas each fork is a separate workspace, they don't have to know each other only when there is a requirement to exchange files.
Let's do the GIT way .
Everyone create branches and develop based on the origin repo (SVN way).
If multiple developers need to work on a big feature which has to based on a same branch, we can take an exception and create a branch on the origin repo.
One feature (bugfix, hotfix...), one branch - [Mandatory] ΒΆ
Branch is designed to be lightweight, normally a branch can be discard after its commits being successfully merged into master branch, don't create long-lived branch (except master).
After merging code to
master, pull code from remotemasterinto current branch and continue next feature developing.
After merging code to
master, I deleted my feature branch, and create a new branch based on remotemasterfor new feature developing.
During feature developing, there comes a bug, so I add the bugfix code to my feature branch.
During feature developing, there comes a bug, so I
stashmy current code, and create a new branch based on remotemasterfor bug fix. After the fix code merged, Istash popand continue feature developing.
Don't do cross branch merge - [Mandatory] ΒΆ
After a commit being crossly merged to different branches, git will generate independent commits on target branch for the merge request (see Merge strategies), and it will cause diff between those branches (see Git diff), which lead to confusion, because in fact they are exactly the same. So, always do one way merge.
Merge
my-branchtodevelopbranch andmasterbranch seperately.
Merge
my-branchtodevelopbranch first, if everything works fine, then mergedevelopbranch tomasterbranch.
Set up certain naming convention for branch name - [Recommend] ΒΆ
- Release Branch: release/{version}
- Feature Branch: feature/{jira-number}-{feature-name}
- Bugfix Branch: bugfix/{jira-number}-{bugfix-name}
- Tag: tag/{version}
- EP Branch: EP/{EP-version}
Use squash merge strategy - [Recommend] ΒΆ
Squash merge keeps a tidy and clean liner commit history, which makes it easy to read and track.
Reference ΒΆ
About collaborative development models
All About Git Cheat sheet of Git
Learn Git Branching Learn Git by playing games