Best practices
Tips & tricks
Rebase & you
Terminal hackery
Slide 3
Slide 3 text
❝ git gets easier once you
get the basic idea that
branches are
homeomorphic
endofunctors mapping
submanifolds of a Hilbert
space ❞
-- The Internet
Slide 4
Slide 4 text
❝ SourceTree sucks ❞
-- Me
Slide 5
Slide 5 text
Best practices
Good
Slide 6
Slide 6 text
commit
commit often
write good commit messages
do not commit unrelated
changes together
Slide 7
Slide 7 text
commit
commit often
write good commit messages
do not commit unrelated
changes together
Slide 8
Slide 8 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 9
Slide 9 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 10
Slide 10 text
* Well, unless the client calls in the last minute to
demand ask you politely to drop a feature
because they fucked up had some issues on
their side.
Something that never happens. Ever. Nope.
branches
Slide 11
Slide 11 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 12
Slide 12 text
.gitignore
know and use .gitignore
committed files cannot be ignored (well, not easily)
https://github.com/github/gitignore
Slide 13
Slide 13 text
git pull
God kills a kitten
every time you do this:
Merge branch 'develop_15.5' of gitlab.ideaknow.com:sab-3-0/bsmobil-
translations into develop_15.5
Slide 14
Slide 14 text
No content
Slide 15
Slide 15 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 16
Slide 16 text
git pull
do it for the kittens
if you need to solve conflicts when pushing/
pulling, you are doing something wrong
Slide 17
Slide 17 text
merge 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
learn (both ways)
fun
Slide 18
Slide 18 text
merge request
revelation
Slide 19
Slide 19 text
merge 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”
“”
Slide 20
Slide 20 text
merge request
be the first to review your own code
learn to criticise and to be criticised
your work != you
open a merge request at any time, even to discuss an upcoming
feature
Slide 21
Slide 21 text
clean history
Slide 22
Slide 22 text
Tips & tricks
Slide 23
Slide 23 text
How do I…
…search all of git history for a string?
git log --all -G
Slide 24
Slide 24 text
How do I…
…find the commit that broke my project?
git bisect start
git bisect good
git bisect bad
Slide 25
Slide 25 text
How do I…
…save current changes for later use without committing
because you need to do something urgent?
git stash
git stash list
git stash pop
git stash apply
Slide 26
Slide 26 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 27
Slide 27 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 28
Slide 28 text
How do I…
…revert all staged and non-staged changes?
(i.e.: all non-committed changes)
git reset --hard
⚠
Slide 29
Slide 29 text
How do I…
…revert the last non-pushed commit?
git reset HEAD^
…revert/modify a previous non-pushed commit?
git rebase -i
Slide 30
Slide 30 text
How do I…
…revert a pushed change?
git revert
Slide 31
Slide 31 text
How do I…
…copy an existing commit (from another branch or
another point in history) ?
git cherry-pick
Slide 32
Slide 32 text
How do I…
…split changes in a single file into multiple commits?
git add -p
Slide 33
Slide 33 text
How do I…
…clean remote branches?
git remote prune origin
git push origin --delete
…delete a remote branch?
Slide 34
Slide 34 text
How do I…
… remove untracked files and directories?
git clean -d -f
⚠
Slide 35
Slide 35 text
How do I…
… show changes introduced by a commit?
git show
… show changes introduced by a merge commit?
git show -m
Slide 36
Slide 36 text
How do I…
… find who the fuck wrote this aberration?
git blame path/to/aberration