Making changes
…or how add, commit, checkout works
HEAD Index Working
Directory
checkout
add
commit reset
Slide 10
Slide 10 text
Grouping changes
…or how to use branches via checkout, branch, merge
A
develop HEAD
Slide 11
Slide 11 text
Grouping changes
…or how to use branches via checkout, branch, merge
A
develop
feature
HEAD
git branch feature
Slide 12
Slide 12 text
Grouping changes
…or how to use branches via checkout, branch, merge
A
develop
feature HEAD
git branch feature
git checkout feature
Slide 13
Slide 13 text
Grouping changes
…or how to use branches via checkout, branch, merge
A
develop
feature HEAD
git branch feature
git checkout feature
git add & git commit
B
Slide 14
Slide 14 text
Grouping changes
…or how to use branches via checkout, branch, merge
A
develop
feature HEAD
git branch feature
git checkout feature
git add & git commit
git add & git commit
B C
Slide 15
Slide 15 text
Grouping changes
…or how to use branches via checkout, branch, merge
A
develop
feature HEAD
git branch feature
git checkout feature
git add & git commit
git add & git commit
…
B C
D E
Slide 16
Slide 16 text
Grouping changes
…or how to use branches via checkout, branch, merge
A
develop
feature
HEAD
git branch feature
git checkout feature
git add & git commit
git add & git commit
…
git checkout develop
B C
D E
Slide 17
Slide 17 text
Grouping changes
…or how to use branches via checkout, branch, merge
A
develop
feature
HEAD
git branch feature
git checkout feature
git add & git commit
git add & git commit
…
git checkout develop
git merge feature
B C
D E F
Slide 18
Slide 18 text
Best practices
Good
Slide 19
Slide 19 text
commit
commit often
write good commit messages
do not commit unrelated
changes together
Slide 20
Slide 20 text
commit
commit often
write good commit messages
do not commit unrelated
changes together
Slide 21
Slide 21 text
branches
anything in master is deployable
anything in develop will be delivered
in the next release *
feature-branches is where
we should commit
Slide 22
Slide 22 text
branches
anything in master is deployable
anything in develop will be delivered
in the next release
feature-branches is where
we should commit
Slide 23
Slide 23 text
branches
It’s ok to have different branch schemes, depends
on client, project, technology…
a common workflow > no workflow at all
keep it simple or people won’t follow the scheme
Slide 24
Slide 24 text
.gitignore
know and use .gitignore
committed files cannot be ignored (well, not easily)
https://github.com/github/gitignore
take a look at git config and .gitattributes as well
Slide 25
Slide 25 text
git pull
God kills a kitten
every time you do this:
Merge branch 'foobar' of github.com:keradgames/goldenmanager-ios
into foobar
Slide 26
Slide 26 text
git pull
git pull is considered harmful
git fetch origin
git rebase origin/develop
git config --global pull.ff only
when changes can’t be applied fast-forward:
Slide 27
Slide 27 text
git pull
do it for the kittens
if you need to solve conflicts when pulling, you are
doing something wrong
Slide 28
Slide 28 text
No content
Slide 29
Slide 29 text
pull request
why?
we all make errors
find logic bugs
high quality code
enforce readable code style
enforce good commit history
let people know what you are
working on (even discuss future
features)
learn (both ways)
fun
Slide 30
Slide 30 text
pull request
useful messages:
“Can we make this more readable?”
“What would be a better name for this method?”
“This needs to be refactored into smaller methods”
“Why did you choose this approach?”
“”
Slide 31
Slide 31 text
Rebase & you
Slide 32
Slide 32 text
Historical revisionism
A B C
D E
develop
feature
Slide 33
Slide 33 text
Historical revisionism
A B C
D E
develop
feature
git checkout feature
git rebase develop
Slide 34
Slide 34 text
Historical revisionism
A B C
D E D’
develop
feature
rebasing (1/2)
Slide 35
Slide 35 text
Historical revisionism
A B C
D E D’ E’
develop
feature
rebasing (2/2)
Slide 36
Slide 36 text
Historical revisionism
A B C
D E D’ E’
develop
feature
rebasing done!
Slide 37
Slide 37 text
Historical revisionism
A B C
D E D’
develop
feature
git rebase -i develop
Slide 38
Slide 38 text
Historical revisionism
A B C
D E E’
develop
feature
git rebase -i develop
Slide 39
Slide 39 text
Historical revisionism
A B C
D E E’ D’
develop
feature
git rebase -i develop
Rebasing dangers
… or when not to use rebase.
Don’t rebase public history.
Think before rebasing long & old branches.
Slide 42
Slide 42 text
Tips & tricks
Slide 43
Slide 43 text
How do I…
…find the commit that broke my project?
git bisect start
git bisect bad
git bisect good
# Bisecting: N revisions left to test after this
(roughly log2(N) steps)
git bisect run
Slide 44
Slide 44 text
How do I…
…save current changes for later use without committing
because you need to do something else?
git stash
git stash list
git stash pop
git stash apply
Slide 45
Slide 45 text
How do I…
…revert a non-staged change?
git checkout -- path/to/file/to/revert
git checkout -- .
…revert all non-staged changes (and nothing else)?
⚠
⚠
Slide 46
Slide 46 text
How do I…
…revert a staged change?
git reset path/to/file/to/revert
git reset
…revert all staged changes (and nothing else)?
Slide 47
Slide 47 text
How do I…
…revert all staged and non-staged changes?
(i.e.: all non-committed changes)
git reset --hard
⚠
Slide 48
Slide 48 text
How do I…
…revert the last non-pushed commit?
git reset HEAD^
…revert/modify a previous non-pushed commit?
git rebase -i
Slide 49
Slide 49 text
How do I…
…revert a pushed/public change?
git revert
Slide 50
Slide 50 text
How do I…
…copy an existing commit (from another branch or
another point in history) ?
git cherry-pick
Slide 51
Slide 51 text
How do I…
…split changes in a single file into multiple commits?
git add -p
# for each hunk: y, n, s, e …
git add -i
Slide 52
Slide 52 text
How do I…
…clean remote branches?
git remote prune origin
git config --global remote.origin.prune true
git push origin --delete
…delete a remote branch?
Slide 53
Slide 53 text
How do I…
… remove untracked files and directories?
git clean -d -f
⚠
Slide 54
Slide 54 text
How do I…
… see changes introduced by a commit?
git show
… see changes introduced by a merge commit?
git show -m
Slide 55
Slide 55 text
How do I…
… find who fucked up modified lines 42 to 84 of this file?
git blame -L 42,84 path/to/file