Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Daily Git

Daily Git

A practical dive into everyday-Git

Gabriele Petronella

September 29, 2015
Tweet

More Decks by Gabriele Petronella

Other Decks in Programming

Transcript

  1. Takeaways » git is powerful, hence hard » git is

    flexible » an idea of the stuff you can do with it
  2. 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
  3. 5. browse the history, examples git log --color git log

    --color --graph git log --color --graph --oneline git log --color --graph --oneline --decorate
  4. 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. 6. ...and get them back git pull --ff # friends

    forever <3 shortcut for git fetch git merge --ff origin/master
  6. 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
  7. 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
  8. master feature ! ! ! ! ! ! "##$##% "##$##%

    ! ! ! ! ! ! ! ! &##'##( &##'##( ! ! ! ! "##$##% "##$##% ! ! !xxxxx! ! ! !xxxxx! &##'##( &#####( ! / ! ________/ "##$##% / ! !/ ! ! &#####(
  9. master ! ! "##$##% !ooooo! !ooooo! feature &#####' ! !

    ! ! "##$##% "##$##% ! ! ! ! ! ! ! ! &##(##' &##(##' ! ! ! ! "##$##% "##$##% ! ! !xxxxx! ! ! !xxxxx! &##(##' &#####' ! / ! ________/ "##$##% / ! !/ ! ! &#####'
  10. 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
  11. 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
  12. 14. undo that‽ Undo last local commit and discard changes

    git reset --hard HEAD~1 Undo last local commit git reset --soft HEAD~1
  13. 15. put things away # stash things away git stash

    -u # get them back git stash [pop|apply]
  14. 16. clean-up branches git rebase -i <some sha> Bonus: find

    the fork point git merge-base --fork-point master
  15. 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
  16. 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/
  17. 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