footer: © The Motley Fool, 2014 slidenumbers: true
- "Those who cannot remember the past are condemned to repeat it."
- Improves teamwork, collaboration, and communication
- Related to just one "changeset"
- Easy to review
- Easy to revert
- Use
git add -i
or GUI tool
- Not for you, for your coworkers
- You may be unavailable and unreachable (another dimension, a zombie, etc).
- You may not work here anymore.
- You may forget.
- Code and version control already shows what you changed
- Need to explain business/use case--what problem are you solving?
- Include names of people, dates, etc of justification
- CYA!!
Summarize what changes do < 50 chars
More detailed explanation, wrapping at ~72 chars, with an empty line between
the "title" and the "body". Explain motivation for changes, and describe
difference between previous state and current state.
- Optionally with bullet points
App icon color change for the business
Meeting with Tom Gardner on 15-Oct-1999. He wants the icon to be
cornflower blue. His reasoning: "Efficiency is priority
number one, people. Because waste is a thief"
Moving the control of the icon color to a setting in the config file
just in case he changes his mind.
^ Date, color, and quotes come from Fight Club. Christian will award 500 gold to whomever names the reference.
- Branches are just pointers, easy to create and delete
- Edits on branch recorded as changes from branch point
- Many branches, single working copy
- Never know how long a change will take
- Working on multiple changes/fixes at the same time
- Easy to switch to emergency work
- Local master always reflects publicly-available code
- Pull often (rebase or merge, discussed later)
- Easier to deal with lots of small changes/conflicts, if any, daily
- If and when priorities change mid-development, there's no annoying cleanup of now-irrelevant code on master
- Delete the branch, or keep it for reference/potential code reuse--either way, the master branch is uncluttered
In the beginning:
$ git checkout -b fix-divide-by-zero origin/master # descriptive name!
While working:
$ git pull # or git pull --rebase
In the end:
$ git rebase -i
$ git checkout master
$ git merge -no-ff fix-divide-by-zero
$ git push
$ git branch -d fix-divide-by-zero
- Holding onto uncommitted changes without dirtying history
- Specific to the branch
- Multiple stashes possible, give them names
- Can be turned into branches
- Useful when need to pull latest without committing
Save
$ git stash
$ git stash save "descriptive name"
Apply
$ git stash pop
$ git stash apply
Creating a branch from stash
$ git stash branch wip-new-stuff stash@{2}
Getting latest without committing
$ git stash && git pull && git stash pop
- Rewinds commits and replays them on top of target commit
- Rewrites history to be linear, and thus more readable
Scenario:
- Your changes are commited but not pushed.
- Changes from others commited and pushed.
- You need to pull before you can push.
- Your changes come first and then everyone else's
- Chronologically might be correct
- Repo perspective wrong
- Their changes come first and then your changes
- Since repo is "The Truth", more accurate depection of events
- Allows you to clean up / edit / reorder commits
- Don't have to care about local history until ready to push
- Commit often locally and reorganize into logical commits later!
$ git rebase -i <branch> <target-commit>
- Creates new commits
- Rebase already pushed commits, others will have a bad day
- Conflicts nonintuitive
- "Local"/"Ours"/"Mine" is the repository
- "Remote"/"Theirs" is YOUR changes
- Potential for more conflicts than merge
- To easily do a fixup or squash on an earlier commit, run:
$ git commit --fixup=<commit-to-fix>
$ git rebase -i --autosquash <branch> <target>
- Automatically places fixup/squash commit on rebase
- To default autosquash on interactive rebase, run:
$ git config --global rebase.autosquash=true
- Local to the checkout
- Records every action git performed where data is stored
- Gives you SHA1 to checkout/cherry-pick/merge from any point in history
- WARNING 'git gc' which runs automagically periodically, cleans the reflog!
2 Strategies
- Release Branches
- Master is Deployable
- New work lands in master
- Each release has a branch
- Specific commits are cherry-picked ("back-ported") into release branches as necessary
- Tags on branches when deployed
- New work is done on feature branches
- Feature branches not merged until tests passed and code reviewed
- All deployments come from master
Processed used by Github to work on Github
- Create a branch
- Add commits
- Rebase -i
- Open a Pull Request (or ask for Code Review)
- Discuss/Review
- Merge (--no-ff)
- Deploy