Git Workflow
Git Workflow
Introduction
In this part of the documentation we will present the internal structure of the git repositories of OSPSuite, as well as the strategy for naming the branches and creating releases.
General
The proposed workflow will use git merge and git rebase for different tasks. Our goal is to establish a workflow that will ensure a clean and useful public history graph. The public history should be concise yet clear and reflect the work of the team in a cohesive way.
We will use git merge to incorporate the entire set of commit of one branch (typically the develop branch) into another one (typically master).
We will use git rebase for all other type of code integration (sub tasks of a given swim lane etc..).
Definition
The
masterbranch is the ultimate source of truth. It should always be possible to use the code onmasterand create a production setup.The
developbranch is the branch where the development is taking place. Ultimately, when a new release is created, the commits indevelopwill be merged back intomaster.A
featurebranch is a short lived branch that is used during the implementation of a given task. It will be deleted once the feature is implemented and merged intodevelop.The git version to use is
1.8.5or newer. This will allow the setting of the configuration optiongit pull -rebase = preserve. This option specify that on pull, rebase should be used instead of merge. But incoming merge commit should be preserved.Unless required otherwise, all work should be performed on a fork of the repository. A Pull Request (PR), will be used to incorporate changes into the
developbranch.
Use Case: Implementing Task "426 it should be possible to delete observed data"
Note: A task is a cohesive unit of work. This can be part of a bigger feature or a bug fix. We assume that a fork of the repository has already been created.
Create a
featurebranch with a meaningful name, starting with the id of the task. We will need to acquire the latest changes from the remotedevelopbranch first and then create the feature branch
With option git pull -rebase = preserve
git checkout develop
git pull upstream #<= git fetch upstream develop && git rebase -p upstream/develop
git checkout -b 426-delete-observed-dataWithout option git pull -rebase = preserve
git checkout develop
git fetch upstream develop
git rebase -p upstream/develop
git checkout -b 426-delete-observed-dataDo work in your
featurebranch, committing early and often.Rebase frequently to incorporate any upstream changes in the
developbranch (to resolve conflicts as early as possible)
git fetch upstream develop
git rebase -p upstream/developOnce work on the feature is complete, you are ready to create a PR. The first step is to push the code to your own repo and then create a PR onto the original repo for review:
git fetch upstream develop
git rebase -p upstream/develop
git push -u origin 426-delete-observed-dataAt that stage, your local branch 426-delete-observed-data is set to track the remote branch 426-delete-observed-data so you will be able to use the simple git push command from now on to update your repo.
Create pull request on github so that your change may be reviewed. The pull request should be between the
developbranch on theupstreamrepo and thefeaturebranch on yourfork. The PR message should use the task id and the whole description of the task. For exampleFixes #426 it should be possible to delete observed data.Upon code review, you may have to change the code slightly to take reviewer comments and concerns into account. If so just continue committing your work on your local
426-delete-observed-databranch and repeat the steps above.Once the latest push has been accepted and all tests are passing, the reviewer can accept the pull request by using the
Squash and Mergeoption. This will effectively squash all your commit into one and rebase the one commit from426-delete-observed-dataontodevelop.Delete your remote branch
426-delete-observed-dataas it is not required anymoreLocally you can now repeat the synchronization of your develop branch
git checkout develop
git pull upstreamYour local
426-delete-observed-datacan also be deleted.
git branch -d 426-delete-observed-dataOptionally you may wish to remove any pointers locally to remote branch that do not exist anymore
git remote prune originA useful alias can be created in git to avoid repeating the same commands again and again for synchronizing remote
developbranch with localfeaturebranch.
[alias]
sync = !git fetch upstream $1 && git rebase upstream/$1
syncd = !git sync developSimply call git syncd to synchronize changes with the develop branch. To synchronize with an hypothetical other branch called experience, use git sync experience
Use Case: Creating a new release 6.5.1
The work on the develop branch is finished and we are ready to tag the version officially. A tagged version will be a version that has been approved for work in production.
This is extremely simple with github using the concept of release.
Click on the
releasessection from theCodetabClick on
Draft new releasePick the
developbranch or the latest commit ondevelopcorresponding to the commit to tagName the tag
v6.5.1.Give a meaningful name to the release
Release 6.5.1Optionally enter a description in the description field. This is typically where release notes should be written using the power of markdown. Files can also be attached to the description (manual, notes etc)
Publish release! Great job
Use Case: Creating a hot fix
Release 6.5.1 has been out for a few weeks and a nasty bug (issue 756 on the bug tracking system) was reported that can corrupt a project file. We need to create a hot fix asap to address the issue. The hot fix should be applied to 6.5.1 obviously, but the actual fix should also be pushed to other branches such as develop
Create a branch based on the tag and create a new branch to collect all fixes for the hotfix
git fetch upstream
git checkout tags/v6.5.1 -b hotfix/6.5.2
git push -u upstream hotfix/6.5.2Create a branch for the one issue to solve
git checkout -b 756-project-corruptedImplement hot fix in this local branch
Push commit to start the code review process
git sync hotfix/6.5.2
git push origin 756-project-corruptedAfter completed review, rebase PR into
hotfix/6.5.2Repeat for all issues that will be part of the hotfix (one or more)
Create release off of
hotfix/6.5.2called Release6.5.2with tagv6.5.2Merge branch
hotfix/6.5.2intodevelop(fixing potential conflicts if any)Delete branch
hotfix/6.5.2
Last updated