Git advanced

33
git-advanced @peter_v 2015-10-08 @RIAnalytics hackaton

Transcript of Git advanced

git-advanced

@peter_v 2015-10-08@RIAnalytics hackaton

disclaimer

● from the trenches● opiniated (git cherry-pick)● not complete● going deep (feel free to disconnect)

contents

● always start with “Why ?”● GitX and other GUI’s● fundamentals● git init, git status, git add -i, git commit● git remote -v, git init --bare● git branch -a, git merge, git rebase -i● git cherry-pick, git log --author

WHY ? (peter_v)

● I <3 git , because now = ∅ + Σ commits● I was there too, so maybe this helps ?

detached head ???

WHY ? (Linus)

Ref https://git-scm.com/book/ca/v1/Comencem-A-Short-History-of-Git

GUI’s for git

● multi-OS : Tower, Github, SourceTree …● Mac : GitX-dev (rowanj fork)● Linux : gitk● I use GitX-dev + command line● overview (next pages):

https://git-scm.com/downloads/guis

GUI’s for git (2)

GUI’s for git (3)

GitX on spark 1.4 : clean - linear

GitX on Rails 4.1 - “creative chaos” ...

remoteremote

fundamentals

working dir

index

repository

remote(s)

git add

git commit

git push

git checkout

git fetch

origin

git merge

⇐ NON-local

⇐ ALL local

upstream

git init

$ git init git-advanced

● creates a repository in ../.git● interesting: config, hooks, logs, refs● does a local git checkout● all state is inside the dir (mv, tar, cp -r, …)

after git init (1)

after git init (2)

working dir

index

repository

remote

git add

git commit

git push

git checkout

git fetch

origin

git merge

after git init (3) - GitX

git status

$ git status

● “safe” command (always first)● files/changes NOT yet in index => red● files/changes in index => green

$ alias gst=’git status’

git status

before git add

working dir

index

repository

remote

git add

git commit

git push

git checkout

git fetch

origin

git merge

git add -i

$ git add -i

● fine grained control of commits● always do “4” first

GOTCHA => new files not shown $%#!(“untracked files”)

git add -i (GOTCHA new files)

git add -i : the beautiful part :-)

git add -i : partial add of “commands”

git status after partial git add

git diff

working dir

index

repository

git diff

git diff --cached

git commit

● what really is it ??● identified by a recursive sha (long, short 7)● relative: a DIFF between “parent” and “this”● absolute: ∅ + Σ (parent) commits● only 1 parent ? NO (merge, non fast-forward)

after git commit

git commit --amend

git remote

● git remote -v● on server

○ mkdir git-advanved.git○ cd git-advanced.git○ git init --bare .

● git remote add origin [email protected]:/data/git/git-advanced.git

git branch

* git branch -a

* git pull = git fetch + git merge

* git rebase origin/master

* fast forward

git ignore

* git ignore in global ~/.git

* cat ~/.gitconfig

* cat ~/.gitignore_global

git rebase -i

* git rebase -i

(--continue --abort --skip)

* clean up large binary commits

* git push force

git rebase vs. merge

* rebase frequently with /01 /02 branches

* squash (git rebase -i) if needed

* tests can be run locally by developer (also possible with "git merge master")

interesting commands

* git cherry-pick

* git log --author MyName