-
Notifications
You must be signed in to change notification settings - Fork 0
Git Forking Workflow
The main advantage of the forking workflow is to keep the main repo safe and clean. Safe as direct pushes to the main repo are disallowed. Only pull requests can be merged by team members into the main repo. Clean as the main repo keeps only a single-thread of history on the master branch free of noises.
Typically the main repo hooks up directly to deployment. On the main repo, the following are expected:
- The master branch
- The release branch (and/or release tags)
- Hot patches made on the release branch and merged back to the master branch
Whereas a fork focuses on development:
- Master branch in sync with that of the main repo
- Dev (or feature) branches
Here is what I call "the git triangle":

This is optional. On the organization's page, click the "Settings" tab, then "Member privileges". Set the default repository permission to "Read".
On the repo's page, click "Settings", then "Branches". Choose the (master) branch to protect. Check "Restrict who can push to this branch" and save the changes.
Here are repo names used in the description of the workflows:
- main: the main repo (note this is often called upstream)
- origin: the developer's fork
-
git checkout master-- check out the local master branch -
git pull --rebase main master-- update the local master branch with that of the main repo, rebase to avoid a merge commit which is unnecessary here -
git push origin master-- update the fork's master branch
Note it recommends to always create a new branch for new development work. That is to say, do not reuse branches for development. The main repo may rewrite development history, for example, by squash merging commits. Syncing up with the main repo after merge creates "shadow" commits on the development branch. To solve the problem always sync up on the master branch. Development is always done on a newly created development branch. The new branch is always merged into the main' master by pull requests. It can be deleted after the work is done (merged).
-
git checkout -b dev-- create a new dev branch of the local master and check it out - Development work
- Send out a pull request on this dev branch
- More development work
- Can be deleted after the pull request is merged and eventually deployed
git checkout mastergit branch -d devgit push origin :dev
The idea is that the master branch is hooked to the integration stack. Commits to the master branch are automatically deployed to the integration stack and are continuously tested.
Whereas the release (or staging) branch is hooked to the staging stack. Specific commits on the master branch can be hand-picked to merge into the release branch. They are automatically deployed to the staging stack as release candidates.
Merging to release is fast-forward only git merge --ff-only <commit>.
A release branch makes it easier to receive hot patches. Patch is made on the release branch and merged back to the master branch.
On a machine devoted to managing releases, or on a local dev box:
- Manage the projects' source in the
~/Workspacefolder, the same as local development, but name the project folder<project>-staging:
$ ls -1 ~/Workspace
<project1>-staging
<project2>-staging
...- For any project, the remote is the "main" remote (i.e. the team's remote):
$ git remote -v
main https://<usr>@github.com/<team>/<project>.git (fetch)
main https://<usr>@github.com/<team>/<project>.git (push)- It has the master branch and the staging branch and the local branches are set to track respective remote branches:
$ git branch -a
master
* staging
remotes/main/master
remotes/main/staging- The steps to release is as following:
# Fetch from remote
$ git fetch main
# Update the local master branch
$ git checkout master
$ git merge --ff-only main/master
# Update the local staging branch
$ git checkout staging
$ git merge --ff-only master
# Push to remote staging
$ git push main stagingWhen updating the local staging branch, can pick a particular commit:
$ git merge --ff-only 27df7f3Releasing to production usually do not build the source any more. Unlike staging, there is no production branch. Production deployment deploys the build artifact.
Assuming you have created account with OSSRH and they accept published artifacts from you. Assuming you have set up Maven (or Gradle) and Travis CI for that.
One action of releasing to the staging branch is that Travis CI will upload the staging artifacts to OSSRH. Read the Travis CI log and make sure the artifacts have been successfully uploaded.
Log in to OSSRH. Check the staging repositories on the Nexus Repository Manager. One of the staging bundles should be yours. Check its content and make sure it is good. Click the "Close" button. This will trigger OSS for a sanity check. If the check passes, the "Release" button will be enabled. Click the "Release" button will release the code to Maven central.

- git-merge -- must read