Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Daily Git
Search
Gabriele Petronella
September 29, 2015
Programming
2
360
Daily Git
A practical dive into everyday-Git
Gabriele Petronella
September 29, 2015
Tweet
Share
More Decks by Gabriele Petronella
See All by Gabriele Petronella
Design System Adventures in React - ReactJS Day 2024
gabro
0
94
Design System Adventures in React
gabro
1
94
Casting Metals
gabro
0
360
Functional Programming in front-end applications
gabro
1
230
Functional Programming in Front-end Applications
gabro
3
180
How to get away with Functional Programming in front-end applications
gabro
3
1.5k
Bridging the tooling gap with Scala.js
gabro
0
270
Monad Transformers Down to Earth
gabro
2
2.6k
Move fast and fix things
gabro
0
330
Other Decks in Programming
See All in Programming
DataformでPythonする / dataform-de-python
snhryt
0
160
Android 15以上でPDFのテキスト検索を爆速開発!
tonionagauzzi
0
200
Terraform やるなら公式スタイルガイドを読もう 〜重要項目 10選〜
hiyanger
12
3k
Nuances on Kubernetes - RubyConf Taiwan 2025
envek
0
140
AIのメモリー
watany
13
1.4k
The State of Fluid (2025)
s2b
0
120
なぜあなたのオブザーバビリティ導入は頓挫するのか
ryota_hnk
5
590
可変性を制する設計: 構造と振る舞いから考える概念モデリングとその実装
a_suenami
10
1.7k
令和最新版手のひらコンピュータ
koba789
13
7.4k
Gemini CLIの"強み"を知る! Gemini CLIとClaude Codeを比較してみた!
kotahisafuru
3
970
あまり知られていない MCP 仕様たち / MCP specifications that aren’t widely known
ktr_0731
0
240
画像コンペでのベースラインモデルの育て方
tattaka
3
1.5k
Featured
See All Featured
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.8k
For a Future-Friendly Web
brad_frost
179
9.9k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
800
Git: the NoSQL Database
bkeepers
PRO
431
65k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
3.1k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
8
450
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.4k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
50
5.5k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.6k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
332
22k
Transcript
daily git gabriele petronella software engineer @ buildo Twitter: @gabro27
/ @buildoHQ
None
Version control & me 2010-2011: svn 2010-today: git
git add git commit git push git pull
That's it
git is simple
Questions?
None
git is hard
git is java
None
git is (like) java learning it is part of your
job
Takeaways » git is powerful, hence hard » git is
flexible » an idea of the stuff you can do with it
the git model
SVN svn add svn commit git git add git commit
git push
enter the stage
None
let's start! (with the basics)
1. create a new repo
1. create a new repo mkdir darepo cd darepo git
init git commit --allow-empty -m "[init]" http://stackoverflow.com/questions/435646/combine-the-first-two-commits-of-a-git-repository
2. check the repo status
2. check the repo status git status
3. add changes to the index
3. add changes to the index git add .gitignore
3. add changes to the index, the cool way) git
add -p
4. save changes
4. save changes git commit -v
4. (bonus) save changes, the cool way git commit -p
5. Browse the history
5. Browse the history git log
5. browse the history, examples git log --color git log
--color --graph git log --color --graph --oneline git log --color --graph --oneline --decorate
5. browse the history, with style git log --graph --full-history
--all --color -- pretty=format:"%x1b[31m%h%x09%x1b[32m%d%x1b[0m%x20%s %x20%C(yellow)(%an, %C(white)%ar)"
5. browse the history, à la GitHub git working-history https://gist.github.com/gabro/5883819
6. save changes remotely
6. save changes remotely... git remote add origin
[email protected]
:buildo/git-talk git
push -u origin master
6. ...and get them back git pull --ff # friends
forever <3 shortcut for git fetch git merge --ff origin/master
7. branching
7. branching git branch a-new-feature git checkout a-new-feature or better
git checkout -b a-new-feature
7. merging a branch git checkout master git merge a-new-feature
7. clean-up behind us # delete a branch locally (and
safely) git branch -d a-new-feature # delete a branch remotely git push origin :a-new-feature bonus git branch --merged master | \ grep -v '\\* master' | xargs -n 1 git branch -d
8. ignore stuff
8. ignore stuff in .gitignore npm_modules
Hey how do I...
9. Selectively ignore stuff
9. Selectively ignore stuff *config.json !example_config.json
9. (bonus) fun with directories . !"" foo #"" ignore_me
!"" include_me !"" .gitkeep
9. (bonus) fun with directories /foo !/foo/include_me vs /foo/* !/foo/include_me
http://stackoverflow.com/a/20652768/846273
10. browse the history of a file
10. browse the history of a file git log --follow
/path/to/file
10. browse the history of lines git log -L 1,+10:file.json
10. browse the history of methods/functions/classes git log -L :methodName:path/to/file
None
10. browse the history of methods/functions/classes in ~/.gitconfig [core] attributesfile
= ~/.gitattributes [diff "scala"] xfuncname = "^\\s*(.*(def|object|class|trait) .*)$" in ~/.gitattributes *.scala diff=scala
11. change the remote repo
11. change the remote repo git remote --set-url origin https://github.com/gabro/another-repo
12. move that commit to master?
master feature ! ! ! ! ! ! "##$##% "##$##%
! ! ! ! ! ! ! ! &##'##( &##'##( ! ! ! ! "##$##% "##$##% ! ! !xxxxx! ! ! !xxxxx! &##'##( &#####( ! / ! ________/ "##$##% / ! !/ ! ! &#####(
master ! ! "##$##% !ooooo! !ooooo! feature &#####' ! !
! ! "##$##% "##$##% ! ! ! ! ! ! ! ! &##(##' &##(##' ! ! ! ! "##$##% "##$##% ! ! !xxxxx! ! ! !xxxxx! &##(##' &#####' ! / ! ________/ "##$##% / ! !/ ! ! &#####'
12. move that commit to master? git checkout master git
cherry-pick 231256
13. move to a branch after I've started working
13. move to a branch after I've started working Well,
if you didn't push...
None
13. move to a branch after I've started working git
commit -m "stuff" ...oh sh*t!... git branch new-feature # mark this point as the new branch git reset --hard HEAD~1 # rewind master
14. undo that‽
14. undo that‽ git regret --hard https://github.com/YtvwlD/git-regret
14. undo that‽ ⾠ Delete changes to the working directory
⾠ git reset --hard ⾠ Restore a file to its last committed version ⾠ git checkout /path/to/file
14. undo that‽ Undo last local commit and discard changes
git reset --hard HEAD~1 Undo last local commit git reset --soft HEAD~1
14. undo that‽ Edit last local commit message git commit
--amend
14. undo that‽ Undo last public commit git revert HEAD
14. undo that‽ Edit last public commit message1 1 git
commit --amend; git push -f
None
15. put things away
15. put things away # stash things away git stash
-u # get them back git stash [pop|apply]
16. clean-up branches
16. clean-up branches git rebase -i <some sha> Bonus: find
the fork point git merge-base --fork-point master
17. blame co-workers
17. blame co-workers git blame /path/to/file
17. blame co-workers (the cool way) # now it's bad,
and it was good 10 commits ago git bisect start HEAD HEAD~10 # for each commit we analyze git bisect [good|bad] git bisect log git bisect reset
18. keep a sane workflow
18. keep a sane workflow » small features » short-lived
branches » after merging, no more rebasing » GitHub Flow 2 2 https://guides.github.com/introduction/flow/
useful references » git-scm.com/docs/git-<command> » man git-<command> » try.github.io »
codeschool.com/paths/git » Git Internals by Scott Chacon 3 3 https://github.com/pluralsight/git-internals-pdf
Thank you
Questions?
[email protected]