TLDR;
- Keep
shippable1
master
- Develop on a branch
- Rebase only on a branch other than master
- Merge development branch back to master
- Use
and1
git fetch
over1
git merge origin master
1
git pull
- Do a dry run before pushing to master:
1
git push --dry-run origin master
Details
Develop on a branch
1
2
3
- On master: `git co -b new_branch`
- (will be switched to new_branch)
- Develop, commit, rebase as needed
Staying up to date
As new changes are committed to master, get them from the server and bring those into the branch before merging back into master.
1
2
3
4
5
- Switch to master `git co master`
(note, the next 3 steps (with the exception of the 2nd) are the same as "git pull")
- `git fetch`
- review newly downloaded changes `git log origin/master`
- merge into master `git merge origin/master`
Getting changes onto the branch
To get the new change into new_branch:
1
2
- Switch to new_branch `git co new_branch`
- `git rebase master`
A breakdown of what rebase does:
- The commits I’ve made to
are “lifted” or “stashed” off of the branch1
new_branch
- A
is performed1
git merge master
- My “lifted” commits are then reapplied
*Note:* If there are conflicts, I am prompted to fix them at this point, on the branch
Work is complete
When I am ready to merge all work done on
back into master I simply do:1
new_branch
1
2
- From new_branch: git co master
- On master: git merge new_branch
Measure twice, cut once
At this point, before pushing code to origin, I do a “dry run” to verify I have the latest changes from master after my last fetch
1
git push --dry-run origin master
Then if all is clean:
1
git push origin master