Skip to content

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 remote master into current branch and continue next feature developing.

πŸ‘ After merging code to master, I deleted my feature branch, and create a new branch based on remote master for 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 stash my current code, and create a new branch based on remote master for bug fix. After the fix code merged, I stash pop and 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-branch to develop branch and master branch seperately.

πŸ‘ Merge my-branch to develop branch first, if everything works fine, then merge develop branch to master branch.

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 ΒΆ

Git Development Process

About collaborative development models

Comparing Workflows

All About Git Cheat sheet of Git

Learn Git Branching Learn Git by playing games