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

Git for champs

Git for champs

A git session at Yodas

Ran Tavory

May 15, 2016
Tweet

More Decks by Ran Tavory

Other Decks in Programming

Transcript

  1. WHY? ➤ Git is a powerful tool. ➤ It’s not

    a burden, it’s a power tool, master it and your life as a dev will be better
  2. GIT BASICS OPERATIONS ➤ Most operations are local ➤ git

    commit ➤ git checkout ➤ git log ➤ git merge ➤ git show ➤ … ➤ Remote operations: ➤ git fetch (and pull) ➤ git push
  3. GIT BASICS - DATABASE ➤ All data in .git tree

    (git object store) ➤ Each commit identified by hash ➤ Integrity (checksums) ➤ Add only (like event-sourcing)
  4. GIT CONFIG ➤ git config (configure current project) ➤ git

    config —global (configure the global .gitconfig file) ➤ git config —list ➤ https://git-scm.com/docs/git-config $ git config --global user.name "John Doe" $ git config --global user.email [email protected]
  5. GIT DIFF ➤ git diff ➤ git diff —cached ➤

    git diff <commit> <path> ➤ git diff <commit> <commit> ➤ https://git-scm.com/docs/git-diff
  6. GIT LOG ➤ git log ➤ git log -p ➤

    git log —stat ➤ git log —graph ➤ git log --pretty=format:"%h - %an, %ar : %s” ➤ git log —author=Bob ➤ git log --after 2.days.ago ➤ … ➤ https://git-scm.com/docs/git-log
  7. GIT BRANCH ➤ git co -b branch-name ➤ git branch

    ➤ git branch -d ➤ … ➤ https://git-scm.com/docs/git-branch
  8. GIT MERGE ➤ git merge ➤ git merge —ff-only ➤

    git rebase ➤ Note: ➤ git pull == git fetch && git merge ➤ https://git-scm.com/docs/git-merge
  9. GIT RESET ➤ git reset —soft ➤ git reset —hard

    (be careful!) ➤ https://git-scm.com/docs/git-reset
  10. GIT REBASE ➤ git rebase master ➤ git rebase -i

    ➤ git pull —rebase ➤ https://git-scm.com/docs/git-rebase
  11. GIT HOOKS ➤ Look at .git/hooks applypatch-msg, pre-applypatch, post-applypatch, pre-commit,

    prepare-commit-msg, commit-msg, post-commit, pre-rebase, post-merge, pre-push, pre-receive, update, post-receive, post-update, push-to-checkout, pre-auto-gc, post-rewrite ➤ https://www.digitalocean.com/community/tutorials/how-to- use-git-hooks-to-automate-development-and-deployment-tasks ➤ https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
  12. GIT TAGS ➤ git tag - list all tags ➤

    git tag -a v1.4 -m "my version 1.4” - create a tag (annotated tag) ➤ git show v1.4 - show a tag ➤ git push origin -- tags - push with tags ➤ https://git-scm.com/book/en/v2/Git-Basics-Tagging
  13. GIT REMOTES ➤ git remote -v - show remotes ➤

    git remote add pb https://github.com/paulboone/ ticgit - add a remote ➤ git remote rm paul - remove a remote ➤ https://git-scm.com/book/en/v2/Git-Basics-Working-with- Remotes
  14. GIT SUBMODULES ➤ git submodule add https://github.com/chaconinc/ DbConnector - Add

    a submodule ➤ Now look into .gitmodules ➤ git clone --recursive https://github.com/chaconinc/ MainProject - Clone a project with submodules ➤ https://git-scm.com/book/en/v2/Git-Tools-Submodules
  15. A FEW USEFUL ALIASES ➤ Update current branch and submodules:

    up = !git pull --rebase --prune $@ && git submodule update --init — recursive ➤ Undo last commit: undo = reset HEAD~1 —mixed ➤ Fix the commit message of the last commit: amend = commit -a —amend ➤ Cleanup of all merged branches: bclean = "!f() { git branch --merged ${1-master} | grep -v " ${1- master}$" | xargs -r git branch -d; }; f” ➤ Go back to master, update and cleanup merge branches: bdone = "!f() { git checkout ${1-master} && git up && git bclean ${1- master}; }; f" ➤ http://haacked.com/archive/2014/07/28/github-flow-aliases/
  16. GITHUB TRICKS ➤ Gists https://gist.github.com/ ➤ hub https://github.com/github/hub ➤ Add

    ?w=1 to view diffs without whitespace ➤ Use t to open a file on github web ➤ Commit history by author: https://github.com/rails/rails/ commits/master?author=dhh ➤ Comparing is powerful: https://github.com/rails/rails/ compare/master@{1.day.ago}...master ➤ y - freeze page when looking at a file ➤ Highlight lines https://github.com/rails/rails/blob/master/activemodel/ lib/active_model.rb#L53-L60 ➤ … there’s plenty of more…