I was recently working on a feature with another developer, and we used a shared git branch. For this project, we use master as the main development branch. We are careful to never develop locally on the master branch. All my local changes are always in a local branch that I merge back into master before pushing. This has worked very well for us.
But I hadn’t worked out a good workflow for using a shared branch, until now. This is my proposed workflow for shared branches with git.
Basically just treat a shared branch like we treat master. That is, never develop on a shared branch. Always branch locally to do development. The workflow should have gone like this:
# (starting on the master branch, with a shared nifty-feature branch
# already pushed to origin)
git checkout nifty-feature
git branch nifty-feature-local
git checkout nifty-feature-local
# (do a bunch of development)
git commit -am 'checkpoint commit'
# (someone else pushes changes to nifty-feature)
git checkout nifty-feature
git pull
git checkout nifty-feature-local
git rebase nifty-feature # to rebase my local branch on top of david's changes
# (do a bunch more development)
git commit -am 'checkpoint commit'
# (do a bunch more development)
git commit -am 'checkpoint commit'
git rebase -i nifty-feature # squash all my checkpoints into one
git checkout nifty-feature
git merge --ff nifty-feature-local # bring over my one commit from my local branch
git push # push that one commit to the shared nifty-feature branch