a painless git workflow
TRANSCRIPT
feature branch
master= production, stable
develop= future production,
QA-grade
dev/cool
branch
feature branch
dev/awesome
develop + cool
commit and push branch regularly
Pull request
review PR, commit any changes to dev/cool,
merge PR into develop, delete dev/cool
“cool” commits
more “awesome” commits
rebase dev/awesome onto develop
dev/awesome now includes
dev/cool features
develop + cool + awesome
Pull request
review PR, commit any changes to dev/awesome,
merge PR into develop, delete dev/awesome
master
Pull request
push to prod
test on dev env
push to staging
test on dev env
the rebase moves things forward
initial “awesome” commitsinitial “awesome” commits
master= production, stable
develop= future production,
QA grade
dev/cool= integration branch
for big feature
branch
integrationbranch
for big feature
feature/neato
dev/cool + neato
Pull request
review PR, commit any changes to neato,
merge PR into dev/cooldelete neato
feature/nifty
sub-feature branches
feature/nifty now includes
dev/neato features
rebase feature/nifty onto dev/cool
the rebase “moves” prior nifty commits past the neato commits(technically, it moves the point where nifty branched off ahead,
and the commits move with it)
nifty commits, batch 1 nifty commits, batch 1
nifty commits, batch 2
dev/cool + neato + nifty
Pull request
review PR, commit any changes to nifty,
merge PR into dev/cooldelete nifty
Pull request
develop
master
Pull request
merge
merge
develop + feature Xdevelop + feature X
+ feature Y
feature X PR merge
rebase
feature Y PR merge
rebase
$ git checkout develop; git pull # make sure my develop is up to date$ git checkout -b dev/cool # create my branch$ vi WarpCore.java FluxCapacitor.java # make changes$ git commit -m “upgraded intake manifold in flux capacitor” WarpCore.java FluxCapacitor.java # commit$ git push origin dev/cool # save changes in shared repo
Then:
· go to github and file a PR for dev/cool· have someone review and merge your PR into develop · have someone delete dev/cool
· other devs using branches off develop now rebase their branches onto develop to get the cool feature· at next commit, other devs who rebased will need to push -f because of the rebase· repeat ad infinitum
Basic Example
Joe and Jill are working on a big feature. Joe does:
$ git checkout develop; git pull # make sure Joe’s develop is up to date$ git checkout -b dev/cool # create an integration branch for a big feature$ git push origin dev/cool # put integration branch in shared repo for Jill$ git checkout -b feature/neato # create sub-feature branch for neato sub-feature$ vi WarpCore.java FluxCapacitor.java # make changes$ git commit -m “upgraded intake manifold in flux capacitor” WarpCore.java FluxCapacitor.java # commit$ git push origin feature/neato # save changes in shared repo
On her own schedule, Jill does:
$ git checkout dev/cool; git pull # get Joe’s integration branch$ git checkout -b feature/nifty # create sub-feature branch for nifty sub-feature$ vi Manifold.java # make changes$ git commit -m “recalibrated intake manifold” Manifold.java # commit$ git push origin feature/nifty # save changes in shared repo
Joe files a PR and gets his neato feature tested and merged into dev/cool. Jill wants to stay up to date:
$ git rebase dev/cool # brings in Joe’s changes and keeps Jill’s commits together, after Joe’s$ vi Tribble.java # more changes$ git commit -m “upped sensitivity to Klingons” Tribble.java$ git push -f origin feature/nifty # save Jill’s changes in shared repo; -f after rebase
When done, Jill files a PR and gets her nifty feature tested and merged into dev/cool.
Then when dev/cool is feature complete, a PR is filed to do integration testing and merge into develop.
Feature Branch Example
· Thou shalt merge down and rebase up· Thou shalt branch for everything (features & bug fixes)· Thou shalt keep thy branches very short-lived· Thou shalt keep master production-grade, ready to deploy, always· Thou shalt push often· Thou shalt pull often· Thou shalt rebase often· Thou shalt not commit directly into develop (penalty: waterboarding)· Thou shalt not commit directly into master (penalty: violent death)· Thou shalt not merge branches without a PR
The Ten Commandments of Git