Slide 1

Slide 1 text

GIT FOR CHAMPS Ran Tavory Yodas

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

GIT BASICS - DATABASE ➤ All data in .git tree (git object store) ➤ Each commit identified by hash ➤ Integrity (checksums) ➤ Add only (like event-sourcing)

Slide 5

Slide 5 text

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]

Slide 6

Slide 6 text

.GITIGNORE ➤ https://git-scm.com/docs/gitignore ➤ https://www.gitignore.io/

Slide 7

Slide 7 text

GIT STAGES

Slide 8

Slide 8 text

GIT DIFF ➤ git diff ➤ git diff —cached ➤ git diff ➤ git diff ➤ https://git-scm.com/docs/git-diff

Slide 9

Slide 9 text

GIT STASH ➤ https://git-scm.com/docs/git-stash

Slide 10

Slide 10 text

GIT STASH ➤ https://git-scm.com/docs/git-stash

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

GIT BRANCH ➤ git co -b branch-name ➤ git branch ➤ git branch -d ➤ … ➤ https://git-scm.com/docs/git-branch

Slide 13

Slide 13 text

GIT MERGE ➤ git merge ➤ git merge —ff-only ➤ git rebase ➤ Note: ➤ git pull == git fetch && git merge ➤ https://git-scm.com/docs/git-merge

Slide 14

Slide 14 text

GIT SHOW ➤ git show ➤ https://git-scm.com/docs/git-show

Slide 15

Slide 15 text

GIT RESET ➤ git reset —soft ➤ git reset —hard (be careful!) ➤ https://git-scm.com/docs/git-reset

Slide 16

Slide 16 text

GIT REBASE ➤ git rebase master ➤ git rebase -i ➤ git pull —rebase ➤ https://git-scm.com/docs/git-rebase

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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/

Slide 22

Slide 22 text

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…

Slide 23

Slide 23 text

REFERENCES ➤ https://git-scm.com/ ➤ http://haacked.com/archive/2014/07/28/github-flow-aliases/ ➤ https://github.com/blog/967-github-secrets ➤ https://github.com/tiimgreen/github-cheat-sheet ➤ This presentation: …