In our previous posts on the CakeDC Git Workflow we shared some insight on how the development strategy works, and how to get the most out of it. But one of the most important benefits it provides is the increased stability and consistency when working alongside others.
Collaboration and Code Review
Working in a team means that you can usually borrow someone else's eyes. In a cooperative and fast-paced environment, you have to. Period. And one situation that typically arises for this case during development is the "code review".
$ git checkout -t origin/feature/1234 $ git checkout -b review/1234 $ git push -u origin review/1234
Here, the reviewer fetched the feature/1234 branch, then created and pushed their own review/1234 branch. Then, they may propose some changes to the original code, for example:
$ git commit -m "Optimized this and that"
Once the review is complete, they'd then simply push their changes, like so:
... rebase ... $ git push
Now you can use their branch, separately of your own, to clearly view the proposed changes.
$ git checkout -t origin/review/1234 $ git diff review/1234 feature/1234
And when everything is done and ready, just merge those changes in.
$ git checkout feature/1234 $ git merge review/1234 ... rebase ... $ git push
Finally, don't forget to always do some cleanup.
$ git branch -d review/1234 $ git push origin :review/1234
Like this, even that single reviewer's commit (assuming it wasn't squashed in some following rebase) is done in different branch, and clearly tied to the ID of the feature, keeping the story of your code clean and consistent for others.
Using our workflow you'll find that both you and your coworkers will delete remote branches quite often. From time to time, it's good to remove references to non-existing remote branches from your local repository, as you don't want to see redundant branches in your git branch -av list. For this, you can simply prune your branches.
$ git remote prune origin
And don't be afraid to be completely thorough when cleaning the repository up, go for it all!
$ git gc && git clean -dfx && git stash clear
No fast forward merges
Sometimes it's just plain tedious to write --no-ff all the time, especially when we can set up git so we only use --ff when required. Via your project's git configuration file, you can either disable fast forwards for all merges directly, like so:
[merge] ff = false
Or, just for selected (permanent in this case) branches only:
[branch "master"] mergeoptions = --no-ff [branch "stage"] mergeoptions = --no-ff [branch "qa"] mergeoptions = --no-ff [branch "develop"] mergeoptions = --no-ff
Then, for those cases where fast forward is desired, just use the --ff switch:
$ git checkout develop $ git pull --ff
This is especially useful when you're collaborating with others, and those commits are flying around between you. Last thing you want is to get bogged down in merge conflicts!