Slide 1

Slide 1 text

Using git to make life easier and code better

Slide 2

Slide 2 text

git(1) NAME git - the stupid content tracker DESCRIPTION Git is a fast, scalable, distributed revision control system with an unusually rich command set that provides both high-level operations and full access to internals.

Slide 3

Slide 3 text

How does git make life easier? ✪ Store and Record changes to files ✪ Compare versions ✪ Play nice with others ✪ Restore previous work ✪ Awesome stuff

Slide 4

Slide 4 text

How does git make code better? ✪ Store and Record changes to files ✭ History of everything changed and why ✪ Manage and compare versions ✭ Context switch. What changed? ✪ Play nice with others ✭ Learn. Collaborate. Share. Review. ✪ Restore previous work ✭ Go back in time. Undo mistakes. ✪ Awesome stuff

Slide 5

Slide 5 text

How does git make code better? ✪ Store and Record changes to files ✭ History of everything changed and why ✪ Manage and compare versions ✭ Context switch. What changed? ✪ Play nice with others ✭ Learn. Collaborate. Share. Review. ✪ Restore previous work ✭ Go back in time. Undo mistakes. ✪ Awesome stuff

Slide 6

Slide 6 text

How does git make code better? ✪ Store and Record changes to files ✭ History of everything changed and why ✪ Manage and compare versions ✭ Context switch. What changed? ✪ Play nice with others ✭ Learn. Collaborate. Share. Review. ✪ Restore previous work ✭ Go back in time. Undo mistakes. ✪ Awesome stuff

Slide 7

Slide 7 text

So git is super cool. yep. got that. How do we get started?

Slide 8

Slide 8 text

Store and Record changes to files ✪ History of everything changed, ever ✭ init ✭ clone ✭ submodule ✭ status ✭ commit ✭ add

Slide 9

Slide 9 text

git init NAME git-init - Create an empty Git repository or reinitialize an existing one SYNOPSIS git init [--bare] SUMMARY repo/.git -> work locally repo.git (bare) -> put on a server

Slide 10

Slide 10 text

git init $ git init talk-git

Slide 11

Slide 11 text

git init $ git init talk-git Initialized empty Git repository in /xxx/talk-git/.git/ $ cd talk-git/ $ git status On branch master Initial commit nothing to commit (create/copy files and use "git add" to track)

Slide 12

Slide 12 text

git init $ git init talk-git Initialized empty Git repository in /xxx/talk-git/.git/ $ cd talk-git/ $ git status On branch master Initial commit nothing to commit (create/copy files and use "git add" to track) $ cd talk-git

Slide 13

Slide 13 text

git init $ git init talk-git Initialized empty Git repository in /xxx/talk-git/.git/ $ cd talk-git/ $ git status On branch master Initial commit nothing to commit (create/copy files and use "git add" to track) $ cd talk-git $ ls -Al

Slide 14

Slide 14 text

git init $ git init talk-git Initialized empty Git repository in /xxx/talk-git/.git/ $ cd talk-git/ $ git status On branch master Initial commit nothing to commit (create/copy files and use "git add" to track) $ cd talk-git $ ls -Al total 4 drwxrwxr-x 7 xxx xxx 4096 Jun 22 16:32 .git

Slide 15

Slide 15 text

git init $ git init talk-git Initialized empty Git repository in /xxx/talk-git/.git/ $ cd talk-git/ $ git status On branch master Initial commit nothing to commit (create/copy files and use "git add" to track) $ cd talk-git $ ls -Al total 4 drwxrwxr-x 7 xxx xxx 4096 Jun 22 16:32 .git $ ls .git

Slide 16

Slide 16 text

git init $ git init talk-git Initialized empty Git repository in /xxx/talk-git/.git/ $ cd talk-git/ $ git status On branch master Initial commit nothing to commit (create/copy files and use "git add" to track) $ cd talk-git $ ls -Al total 4 drwxrwxr-x 7 xxx xxx 4096 Jun 22 16:32 .git $ ls .git branches config description HEAD hooks info objects refs

Slide 17

Slide 17 text

git init $ git init talk-git Initialized empty Git repository in /xxx/talk-git/.git/ $ cd talk-git/ $ git status On branch master Initial commit nothing to commit (create/copy files and use "git add" to track) $ cd talk-git $ ls -Al total 4 drwxrwxr-x 7 xxx xxx 4096 Jun 22 16:32 .git $ ls .git branches config description HEAD hooks info objects refs $ vim .git/config

Slide 18

Slide 18 text

git init $ git init talk-git Initialized empty Git repository in /xxx/src/talk-git/.git/ $ cd talk-git/ $ git status On branch master Initial commit nothing to commit (create/copy files and use "git add" to track) $ cd talk-git $ ls -Al total 4 drwxrwxr-x 7 xxx xxx 4096 Jun 22 16:32 .git $ ls .git branches config description HEAD hooks info objects refs $ vim .git/config [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true

Slide 19

Slide 19 text

git init .git/config <- where your git preferences are stored for the repo .git/HEAD <- where your work tree points to .git/description .git/refs/ <- where your branches point to .git/hooks/ <- automation scripts .git/branches/ .git/objects/ <- data lives here .git/log/ <- history of your git activities .git/info/

Slide 20

Slide 20 text

.git is a collection of text files ....and objects (BLOBs)

Slide 21

Slide 21 text

git clone NAME git-clone - Clone a repository into a new directory SYNOPSIS git clone [--bare] [--depth ] SUMMARY Copy of another repo --bare is the same as with git init --depth lets you pick less commits (useful for checking out with no history) Try it out! - https://github.com/

Slide 22

Slide 22 text

git clone $ git clone https://github.com/xxx/talk-git

Slide 23

Slide 23 text

git clone $ git clone https://github.com/xxx/talk-git Cloning into 'talk-git'... remote: Counting objects: 3, done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), done. Checking connectivity... done. Initial commit

Slide 24

Slide 24 text

git clone $ git clone https://github.com/xxx/talk-git Cloning into 'talk-git'... remote: Counting objects: 3, done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), done. Checking connectivity... done. $ ls Initial commit

Slide 25

Slide 25 text

git clone $ git clone https://github.com/xxx/talk-git Cloning into 'talk-git'... remote: Counting objects: 3, done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), done. Checking connectivity... done. $ ls README.md Initial commit

Slide 26

Slide 26 text

git clone $ git clone https://github.com/xxx/talk-git Cloning into 'talk-git'... remote: Counting objects: 3, done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), done. Checking connectivity... done. $ ls README.md $ vim .git/config Initial commit

Slide 27

Slide 27 text

git clone $ git clone https://github.com/xxx/talk-git Cloning into 'talk-git'... remote: Counting objects: 3, done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), done. Checking connectivity... done. $ ls README.md $ vim .git/config [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "origin"] url = https://github.com/xxx/talk-git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master Initial commit

Slide 28

Slide 28 text

git clone .git/index <- binary file (references to BLOBs) .git/refs/heads/master <- points to a commit for a local branch .git/refs/remotes/origin .git/refs/remotes/origin/HEAD <- points to a commit for a remote branch .git/packed-refs/ .git/logs/HEAD <- logging your activities .git/logs/refs/remotes .git/logs/refs/heads/master .git/logs/refs/remotes/origin .git/logs/refs/remotes/origin/HEAD .git/objects/47 .git/objects/cd .git/objects/dd .git/objects/47/dbdf0659a968efffdd743224af011882db2e2b <- Actual data for files .git/objects/cd/e833ef40e01cc2393cf65b2f12bcc0409d7332 .git/objects/dd/0a9b447f57d7965f088865b987e6e91a5f824b http://stackoverflow.com/questions/4084921/what-does-the-git-index-contain-exactly

Slide 29

Slide 29 text

git clone allows you to build on existing work

Slide 30

Slide 30 text

git submodule NAME git-submodule - Initialize, update or inspect submodules SYNOPSIS git submodule add [] SUMMARY Copy of a repo INSIDE another repo Submodules allow foreign repositories to be embedded within a subdirectory of the source tree

Slide 31

Slide 31 text

git submodule $ git submodule add [email protected]:agross/git-bisect-demo.git DEPENDENCIES Initial commit

Slide 32

Slide 32 text

git submodule $ git submodule add [email protected]:agross/git-bisect-demo.git Cloning into 'git-bisect-demo'… remote: Counting objects: 340, done. remote: Compressing objects: 100% (237/237), done. remote: Total 340 (delta 91), reused 340 (delta 91), pack-reused 0 Receiving objects: 100% (340/340), 1.29 MiB | 507.00 KiB/s, done. Resolving deltas: 100% (91/91), done. Checking connectivity... done. DEPENDENCIES Initial commit

Slide 33

Slide 33 text

git submodule $ git submodule add [email protected]:agross/git-bisect-demo.git Cloning into 'git-bisect-demo'… remote: Counting objects: 340, done. remote: Compressing objects: 100% (237/237), done. remote: Total 340 (delta 91), reused 340 (delta 91), pack-reused 0 Receiving objects: 100% (340/340), 1.29 MiB | 507.00 KiB/s, done. Resolving deltas: 100% (91/91), done. Checking connectivity... done. $ vim .git/config DEPENDENCIES Initial commit

Slide 34

Slide 34 text

git submodule $ git submodule add [email protected]:agross/git-bisect-demo.git Cloning into 'git-bisect-demo'… remote: Counting objects: 340, done. remote: Compressing objects: 100% (237/237), done. remote: Total 340 (delta 91), reused 340 (delta 91), pack-reused 0 Receiving objects: 100% (340/340), 1.29 MiB | 507.00 KiB/s, done. Resolving deltas: 100% (91/91), done. Checking connectivity... done. $ vim .git/config [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "origin"] url = https://github.com/xxx/talk-git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master [submodule "git-bisect-demo"] url = [email protected]:agross/git-bisect-demo.git DEPENDENCIES Initial commit

Slide 35

Slide 35 text

git submodule $ ls -A DEPENDENCIES Initial commit

Slide 36

Slide 36 text

git submodule $ ls -A .git git-bisect-demo .gitmodules README.md DEPENDENCIES Initial commit

Slide 37

Slide 37 text

git submodule $ ls -A .git git-bisect-demo .gitmodules README.md $ vim .gitmodules DEPENDENCIES Initial commit

Slide 38

Slide 38 text

git submodule $ ls -A .git git-bisect-demo .gitmodules README.md $ vim .gitmodules [submodule "git-bisect-demo"] path = git-bisect-demo url = [email protected]:agross/git-bisect-demo.git DEPENDENCIES Initial commit

Slide 39

Slide 39 text

git submodule .git/index <- binary file representing current state .git/modules .git/modules/git-bisect-demo <- clone of the github repo .git/modules/git-bisect-demo/branches .git/modules/git-bisect-demo/config .git/modules/git-bisect-demo/description ... .git/objects/9f .git/objects/9f/cb792aad6767c2e7346e1e41391761bc71ceb5 .gitmodules <- stores module metadata

Slide 40

Slide 40 text

git submodule allows you to build on existing work, with a separate source tree

Slide 41

Slide 41 text

git submodule allows you to build on existing work, with a separate source tree ....but use composer. Seriously.

Slide 42

Slide 42 text

git status NAME git-status - Show the working tree status SYNOPSIS git status [...] [...] SUMMARY Displays: staged changes (index) unstaged changes untracked files

Slide 43

Slide 43 text

git status $ ls Initial commit

Slide 44

Slide 44 text

git status $ ls git-bisect-demo README.md Initial commit

Slide 45

Slide 45 text

git status $ ls git-bisect-demo README.md $ git status Initial commit

Slide 46

Slide 46 text

git status $ ls git-bisect-demo README.md $ git status On branch master Your branch is up-to-date with 'origin/master'. Changes to be committed: (use "git reset HEAD ..." to unstage) new file: .gitmodules <-staged changes new file: git-bisect-demo <-staged changes Untracked files: (use "git add ..." to include in what will be committed) Initial commit

Slide 47

Slide 47 text

git status $ ls git-bisect-demo README.md $ git status On branch master Your branch is up-to-date with 'origin/master'. Changes to be committed: (use "git reset HEAD ..." to unstage) new file: .gitmodules <-staged changes new file: git-bisect-demo <-staged changes Untracked files: (use "git add ..." to include in what will be committed) Initial commit

Slide 48

Slide 48 text

git status $ echo Hi\!, I’m Alice. > alice.txt Initial commit

Slide 49

Slide 49 text

git status $ echo Hi\!, I’m Alice. > alice.txt $ git status Initial commit

Slide 50

Slide 50 text

git status $ echo Hi\!, I’m Alice. > alice.txt $ git status On branch master Your branch is up-to-date with 'origin/master'. Changes to be committed: (use "git reset HEAD ..." to unstage) new file: .gitmodules <-staged changes new file: git-bisect-demo <-staged changes Untracked files: (use "git add ..." to include in what will be committed) alice.txt <-unstaged changes Initial commit

Slide 51

Slide 51 text

git status tells you what has changed since the last commit staged or unstaged

Slide 52

Slide 52 text

git commit NAME git-commit - Record changes to the repository SYNOPSIS git commit git commit -m git commit --patch SUMMARY -m will shortcut the commit message --patch for cleaner history (small chunks)

Slide 53

Slide 53 text

What is a commit? ✪ A version of all your files at one point in time ✪ Record of who did what, when ✭ Author ✭ Committer ✭ Date ✭ Subject / Description ✪ Has a parent commit ✪ Stored as collections of trees and BLOBs (objects) ✪ Referenced by a SHA-1 hash of it’s contents

Slide 54

Slide 54 text

What is a commit? https://git-scm.com/book/en/v1/Git-Branching-What-a-Branch-Is

Slide 55

Slide 55 text

What is a commit? https://git-scm.com/book/en/v1/Git-Branching-What-a-Branch-Is

Slide 56

Slide 56 text

What is a commit?

Slide 57

Slide 57 text

How should I write a commit? ✪ One commit, one idea ✪ Subject line (the what) ✭ Limit to 50 chars ✭ This commit will... your subject line here ✮ Refactor subsystem X for readability (imperative voice) ✮ more fixes for broken stuff (indicative voice, unclear) ✪ Body provides context (the why) ✭ Wrap at 72 chars http://chris.beams.io/posts/git-commit/

Slide 58

Slide 58 text

git commit $ git commit Initial commit

Slide 59

Slide 59 text

git commit $ git commit Add git-bisect-demo as a submodule # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch master # Your branch is up-to-date with 'origin/master'. # # Changes to be committed: # new file: .gitmodules # new file: git-bisect-demo # # Untracked files: # alice.txt Initial commit

Slide 60

Slide 60 text

git commit $ git commit Add git-bisect-demo as a submodule # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch master # Your branch is up-to-date with 'origin/master'. # # Changes to be committed: # new file: .gitmodules # new file: git-bisect-demo # # Untracked files: # alice.txt [master 24c8660] Add git-bisect-demo as a submodule 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 git-bisect-demo Initial commit git-bisect-demo

Slide 61

Slide 61 text

git commit .git/COMMIT_EDITMSG <- Your commit message .git/HEAD <- points to current commit .git/index <- Staged changes .git/refs/heads/master <- master branch has moved .git/objects/9f <- MOAR data .git/objects/9f/cb792aad6767c2e7346e1e41391761bc71ceb5 http://stackoverflow.com/questions/17595524/orig-head-fetch-head-merge-head-etc

Slide 62

Slide 62 text

git commit writes your staged changes to the repository

Slide 63

Slide 63 text

git add NAME git-add - Add file contents to the index SYNOPSIS git add [--patch | -p] [--update | -u]] SUMMARY --patch for cleaner history (small chunks) --update only work with files in the index useful for deleting files

Slide 64

Slide 64 text

git add $ git status Initial commit git-bisect-demo

Slide 65

Slide 65 text

git add $ git status On branch master Your branch is ahead of 'origin/master' by 1 commit. (use "git push" to publish your local commits) Untracked files: (use "git add ..." to include in what will be committed) alice.txt nothing added to commit but untracked files present (use "git add" to track) Initial commit git-bisect-demo

Slide 66

Slide 66 text

git add $ git add alice.txt Initial commit git-bisect-demo

Slide 67

Slide 67 text

git add $ git add alice.txt $ git status On branch master Your branch is ahead of 'origin/master' by 1 commit. (use "git push" to publish your local commits) Changes to be committed: (use "git reset HEAD ..." to unstage) new file: alice.txt Initial commit git-bisect-demo

Slide 68

Slide 68 text

git add .git/COMMIT_EDITMSG <- Your commit message .git/index <- Staged changes

Slide 69

Slide 69 text

git add+commit $ git add alice.txt $ git status On branch master Your branch is ahead of 'origin/master' by 1 commit. (use "git push" to publish your local commits) Changes to be committed: (use "git reset HEAD ..." to unstage) new file: alice.txt $ git commit -m 'Add alice.txt' Initial commit git-bisect-demo

Slide 70

Slide 70 text

git add+commit $ git add alice.txt $ git status On branch master Your branch is ahead of 'origin/master' by 1 commit. (use "git push" to publish your local commits) Changes to be committed: (use "git reset HEAD ..." to unstage) new file: alice.txt $ git commit -m 'Add alice.txt' [master 712cc39] Add alice.txt 1 file changed, 1 insertion(+) create mode 100644 alice.txt Initial commit git-bisect-demo alice

Slide 71

Slide 71 text

git add+commit $ git add alice.txt $ git status On branch master Your branch is ahead of 'origin/master' by 1 commit. (use "git push" to publish your local commits) Changes to be committed: (use "git reset HEAD ..." to unstage) new file: alice.txt $ git commit -m 'Add alice.txt' [master 712cc39] Add alice.txt 1 file changed, 1 insertion(+) create mode 100644 alice.txt Initial commit git-bisect-demo alice

Slide 72

Slide 72 text

git add+commit $ git add alice.txt $ git status On branch master Your branch is ahead of 'origin/master' by 1 commit. (use "git push" to publish your local commits) Changes to be committed: (use "git reset HEAD ..." to unstage) new file: alice.txt $ git commit -m 'Add alice.txt' [master 712cc39] Add alice.txt 1 file changed, 1 insertion(+) create mode 100644 alice.txt $ git status Initial commit git-bisect-demo alice

Slide 73

Slide 73 text

git add+commit $ git add alice.txt $ git status On branch master Your branch is ahead of 'origin/master' by 1 commit. (use "git push" to publish your local commits) Changes to be committed: (use "git reset HEAD ..." to unstage) new file: alice.txt $ git commit -m 'Add alice.txt' [master 712cc39] Add alice.txt 1 file changed, 1 insertion(+) create mode 100644 alice.txt $ git status On branch master Your branch is ahead of 'origin/master' by 2 commits. (use "git push" to publish your local commits) nothing to commit, working directory clean Initial commit git-bisect-demo alice

Slide 74

Slide 74 text

git add stages changes by modifying .git/index ...so you can commit them.

Slide 75

Slide 75 text

Store and record changes to files ...What do I do with this stuff?

Slide 76

Slide 76 text

Manage and compare versions ✪ Context switch. What changed? ✭ branch ✭ tag ✭ checkout ✭ diff

Slide 77

Slide 77 text

git branch NAME git-branch - List, create, or delete branches SYNOPSIS git branch (-a | -r) git branch (-d | -D) SUMMARY git branch lists branches git branch creates a branch git branch -d deletes a branch

Slide 78

Slide 78 text

What is a branch? ✪ Divergent line of work ✭ master ✭ release / develop ✭ feature / hotfix ✪ A text file ✪ A bookmark ✭ points to a commit ✭ moves when you make another commit on top

Slide 79

Slide 79 text

What is a branch? https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow

Slide 80

Slide 80 text

git branch $ git branch -a Initial commit git-bisect-demo alice

Slide 81

Slide 81 text

git branch $ git branch -a * master remotes/origin/HEAD -> origin/master remotes/origin/master Initial commit git-bisect-demo alice remotes/origin/master master

Slide 82

Slide 82 text

git branch $ git branch -a * master remotes/origin/HEAD -> origin/master remotes/origin/master $ git branch randombranch Initial commit git-bisect-demo alice remotes/origin/master master

Slide 83

Slide 83 text

git branch $ git branch -a * master remotes/origin/HEAD -> origin/master remotes/origin/master $ git branch randombranch Initial commit git-bisect-demo alice remotes/origin/master master randombranch

Slide 84

Slide 84 text

git branch $ git branch -a * master remotes/origin/HEAD -> origin/master remotes/origin/master $ git branch randombranch $ git branch alice-interests Initial commit git-bisect-demo alice remotes/origin/master master randombranch

Slide 85

Slide 85 text

git branch $ git branch -a * master remotes/origin/HEAD -> origin/master remotes/origin/master $ git branch randombranch $ git branch alice-interests Initial commit git-bisect-demo alice remotes/origin/master master randombranch alice-interests

Slide 86

Slide 86 text

git branch $ git branch -a * master remotes/origin/HEAD -> origin/master remotes/origin/master $ git branch randombranch $ git branch alice-interests $ git branch -d randombranch Initial commit git-bisect-demo alice remotes/origin/master master randombranch alice-interests

Slide 87

Slide 87 text

git branch $ git branch -a * master remotes/origin/HEAD -> origin/master remotes/origin/master $ git branch randombranch $ git branch alice-interests $ git branch -d randombranch Initial commit git-bisect-demo alice remotes/origin/master master randombranch alice-interests

Slide 88

Slide 88 text

git branch $ git branch -a * master remotes/origin/HEAD -> origin/master remotes/origin/master $ git branch randombranch $ git branch alice-interests $ git branch -d randombranch Deleted branch randombranch (was 712cc39). Initial commit git-bisect-demo alice remotes/origin/master master alice-interests

Slide 89

Slide 89 text

git branch .git/refs/heads/alice-interests <- points to position of branch HEAD .git/logs/refs/heads/alice-interests <- tracks movement of HEAD over time

Slide 90

Slide 90 text

git branch creates a bookmark to track divergent lines of work

Slide 91

Slide 91 text

What is a tag? ✪ Marker ✭ release version ✭ bug / working version ✭ diff base ✪ A text file ✪ A fixed-in-stone-bookmark ✭ points to a commit ✭ does not move as new commits are added

Slide 92

Slide 92 text

What is a tag? https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow

Slide 93

Slide 93 text

git tag creates a marker that does not move

Slide 94

Slide 94 text

git checkout NAME git-checkout - Checkout a branch or paths to the working tree SYNOPSIS git checkout [] [...] SUMMARY git checkout jump to branch, checkout all files git checkout ... don’t jump to branch, checkout specific files (NOTE:You can swap for a branch/tag)

Slide 95

Slide 95 text

git checkout $ git checkout alice-interests Initial commit git-bisect-demo alice remotes/origin/master master alice-interests

Slide 96

Slide 96 text

git checkout $ git checkout alice-interests Switched to branch 'alice-interests' Initial commit git-bisect-demo alice remotes/origin/master master alice-interests

Slide 97

Slide 97 text

git checkout $ git checkout alice-interests Switched to branch 'alice-interests' $ echo -e "\nI like rainbows." >> alice.txt Initial commit git-bisect-demo alice remotes/origin/master master alice-interests

Slide 98

Slide 98 text

git checkout $ git checkout alice-interests Switched to branch 'alice-interests' $ echo -e "\nI like rainbows." >> alice.txt $ git add alice.txt Initial commit git-bisect-demo alice remotes/origin/master master alice-interests

Slide 99

Slide 99 text

git checkout $ git checkout alice-interests Switched to branch 'alice-interests' $ echo -e "\nI like rainbows." >> alice.txt $ git add alice.txt $ git commit -m "Note that Alice likes rainbows." Initial commit git-bisect-demo alice remotes/origin/master master alice-interests

Slide 100

Slide 100 text

git checkout $ git checkout alice-interests Switched to branch 'alice-interests' $ echo -e "\nI like rainbows." >> alice.txt $ git add alice.txt $ git commit -m "Note that Alice likes rainbows." [alice-interests 1593781] Note that Alice likes rainbows. 1 file changed, 3 insertions(+) Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows

Slide 101

Slide 101 text

git checkout $ cat alice.txt Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows

Slide 102

Slide 102 text

git checkout $ cat alice.txt Hi!, I’m Alice. I like rainbows. Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows

Slide 103

Slide 103 text

git checkout $ cat alice.txt Hi!, I’m Alice. I like rainbows. $ git checkout master alice.txt Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows

Slide 104

Slide 104 text

git checkout $ cat alice.txt Hi!, I’m Alice. I like rainbows. $ git checkout master alice.txt $ cat alice.txt Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows

Slide 105

Slide 105 text

git checkout $ cat alice.txt Hi!, I’m Alice. I like rainbows. $ git checkout master alice.txt $ cat alice.txt Hi!, I’m Alice. Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows

Slide 106

Slide 106 text

git checkout $ cat alice.txt Hi!, I’m Alice. I like rainbows. $ git checkout master alice.txt $ cat alice.txt Hi!, I’m Alice. $ git checkout HEAD alice.txt Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows

Slide 107

Slide 107 text

git checkout $ cat alice.txt Hi!, I’m Alice. I like rainbows. $ git checkout master alice.txt $ cat alice.txt Hi!, I’m Alice. $ git checkout HEAD alice.txt $ cat alice.txt Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows http://stackoverflow.com/questions/17595524/orig-head-fetch-head-merge-head-etc

Slide 108

Slide 108 text

git checkout $ cat alice.txt Hi!, I’m Alice. I like rainbows. $ git checkout master alice.txt $ cat alice.txt Hi!, I’m Alice. $ git checkout HEAD alice.txt $ cat alice.txt Hi!, I’m Alice. I like rainbows. Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows http://stackoverflow.com/questions/17595524/orig-head-fetch-head-merge-head-etc

Slide 109

Slide 109 text

git checkout .git/refs/heads/alice-interests <- points to position of branch HEAD .git/logs/refs/heads/alice-interests <- tracks movement of HEAD over time (Nothing changes if it’s just a file)

Slide 110

Slide 110 text

git checkout checks out branches or files

Slide 111

Slide 111 text

git diff NAME git-diff - Show changes between commits, commit and working tree, etc SYNOPSIS git diff [] git diff --cached [] SUMMARY git diff [] compares work tree git diff --cached [] compares index (NOTE:You can swap for a branch/tag)

Slide 112

Slide 112 text

git diff $ echo -e "\nI also like unicorns." >> alice.txt Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows

Slide 113

Slide 113 text

git diff $ echo -e "\nI also like unicorns." >> alice.txt $ git status Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows

Slide 114

Slide 114 text

git diff $ echo -e "\nI also like unicorns." >> alice.txt $ git status On branch alice-interests Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: alice.txt no changes added to commit (use "git add" and/or "git commit -a") Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows

Slide 115

Slide 115 text

git diff $ echo -e "\nI also like unicorns." >> alice.txt $ git status On branch alice-interests Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: alice.txt no changes added to commit (use "git add" and/or "git commit -a") $ git diff Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows

Slide 116

Slide 116 text

git diff $ echo -e "\nI also like unicorns." >> alice.txt $ git status On branch alice-interests Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: alice.txt no changes added to commit (use "git add" and/or "git commit -a") $ git diff diff --git a/alice.txt b/alice.txt index ac97c89..3da64f6 100644 --- a/alice.txt +++ b/alice.txt @@ -1,3 +1,5 @@ Hi!, I’m Alice. I like rainbows. + +I also like unicorns. Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows

Slide 117

Slide 117 text

git diff $ git add . Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows

Slide 118

Slide 118 text

git diff $ git add . Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows

Slide 119

Slide 119 text

git diff $ git add . $ git status Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows

Slide 120

Slide 120 text

git diff $ git add . $ git status On branch alice-interests Changes to be committed: (use "git reset HEAD ..." to unstage) modified: alice.txt Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows

Slide 121

Slide 121 text

git diff $ git add . $ git status On branch alice-interests Changes to be committed: (use "git reset HEAD ..." to unstage) modified: alice.txt $ git diff Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows

Slide 122

Slide 122 text

git diff $ git add . $ git status On branch alice-interests Changes to be committed: (use "git reset HEAD ..." to unstage) modified: alice.txt $ git diff $ git diff --cached Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows

Slide 123

Slide 123 text

git diff $ git add . $ git status On branch alice-interests Changes to be committed: (use "git reset HEAD ..." to unstage) modified: alice.txt $ git diff $ git diff --cached diff --git a/alice.txt b/alice.txt index ac97c89..3da64f6 100644 --- a/alice.txt +++ b/alice.txt @@ -1,3 +1,5 @@ Hi!, I’m Alice. I like rainbows. + +I also like unicorns. Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows

Slide 124

Slide 124 text

git diff $ git add . $ git status On branch alice-interests Changes to be committed: (use "git reset HEAD ..." to unstage) modified: alice.txt $ git diff $ git diff --cached diff --git a/alice.txt b/alice.txt index ac97c89..3da64f6 100644 --- a/alice.txt +++ b/alice.txt @@ -1,3 +1,5 @@ Hi!, I’m Alice. I like rainbows. + +I also like unicorns. Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows

Slide 125

Slide 125 text

git diff $ git commit -m "Note that alice also likes unicorns" Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows

Slide 126

Slide 126 text

git diff $ git commit -m "Note that alice also likes unicorns" [alice-interests 047fc66] Note that alice also likes unicorns 1 file changed, 2 insertions(+) Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows unicorns

Slide 127

Slide 127 text

git diff $ git commit -m "Note that alice also likes unicorns" [alice-interests 047fc66] Note that alice also likes unicorns 1 file changed, 2 insertions(+) $ git diff master Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows unicorns

Slide 128

Slide 128 text

git diff $ git commit -m "Note that alice also likes unicorns" [alice-interests 047fc66] Note that alice also likes unicorns 1 file changed, 2 insertions(+) $ git diff master diff --git a/alice.txt b/alice.txt index f463940..3da64f6 100644 --- a/alice.txt +++ b/alice.txt @@ -1 +1,5 @@ Hi!, I’m Alice. + +I like rainbows. + +I also like unicorns. Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows unicorns

Slide 129

Slide 129 text

git diff compares the work tree to a branch ...defaulting to HEAD

Slide 130

Slide 130 text

Manage and compare versions ...How can I share these?

Slide 131

Slide 131 text

Playing nicely with others ✪ Learn. Collaborate. Share. Review ✭ push ✭ fetch ✭ merge ✮ fast forward ✮ 3-way ✭ pull (fetch + merge) ✭ cherry-pick ✭ rebase ✮ Lots of cherry picks

Slide 132

Slide 132 text

git push NAME git-push - Update remote refs along with associated objects SYNOPSIS git push [ :] SUMMARY Allows you to share your code Can specify remote - where to push to source - local branch destination - remote branch

Slide 133

Slide 133 text

git push $ git checkout master Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows unicorns

Slide 134

Slide 134 text

git push $ git checkout master Switched to branch 'master' Your branch is ahead of 'origin/master' by 2 commits. (use "git push" to publish your local commits) Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows unicorns

Slide 135

Slide 135 text

git push $ git checkout master Switched to branch 'master' Your branch is ahead of 'origin/master' by 2 commits. (use "git push" to publish your local commits) $ git push Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows unicorns

Slide 136

Slide 136 text

git push $ git checkout master Switched to branch 'master' Your branch is ahead of 'origin/master' by 2 commits. (use "git push" to publish your local commits) $ git push Counting objects: 6, done. Delta compression using up to 4 threads. Compressing objects: 100% (5/5), done. Writing objects: 100% (6/6), 651 bytes | 0 bytes/s, done. Total 6 (delta 1), reused 0 (delta 0) To https://github.com/xxx/talk-git cde833e..712cc39 master -> master Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows unicorns

Slide 137

Slide 137 text

git push $ git checkout master Switched to branch 'master' Your branch is ahead of 'origin/master' by 2 commits. (use "git push" to publish your local commits) $ git push Counting objects: 6, done. Delta compression using up to 4 threads. Compressing objects: 100% (5/5), done. Writing objects: 100% (6/6), 651 bytes | 0 bytes/s, done. Total 6 (delta 1), reused 0 (delta 0) To https://github.com/xxx/talk-git cde833e..712cc39 master -> master Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows unicorns

Slide 138

Slide 138 text

git push $ git checkout master Switched to branch 'master' Your branch is ahead of 'origin/master' by 2 commits. (use "git push" to publish your local commits) $ git push Counting objects: 6, done. Delta compression using up to 4 threads. Compressing objects: 100% (5/5), done. Writing objects: 100% (6/6), 651 bytes | 0 bytes/s, done. Total 6 (delta 1), reused 0 (delta 0) To https://github.com/xxx/talk-git cde833e..712cc39 master -> master // (remote local-source:remote-destination) //Same as $ git push origin master:master Initial commit git-bisect-demo alice remotes/origin/master master alice-interests rainbows unicorns

Slide 139

Slide 139 text

git push .git/refs/remotes/origin/master <- points to position of branch HEAD .git/logs/refs/remotes/origin/master <- tracks movement of HEAD over time

Slide 140

Slide 140 text

git push uploads your changes to a remote repository

Slide 141

Slide 141 text

If Bob pushes to master, how do I integrate his changes?

Slide 142

Slide 142 text

git fetch NAME git-fetch - Download objects and refs from another repository SYNOPSIS git fetch [ :] SUMMARY Allows you to get someone else’s code Can specify remote - where to download from source - remote branch destination - local branch

Slide 143

Slide 143 text

git fetch alice remotes/origin/master master alice-interests rainbows unicorns $ git fetch

Slide 144

Slide 144 text

$ git fetch remote: Counting objects: 3, done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), done. From https://github.com/xxx/talk-git 712cc39..ca980cb master -> origin/master git fetch alice remotes/origin/master master alice-interests rainbows unicorns hates

Slide 145

Slide 145 text

$ git fetch remote: Counting objects: 3, done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), done. From https://github.com/xxx/talk-git 712cc39..ca980cb master -> origin/master //Same as $ git fetch origin master:master // (remote remote-source:local-destination) git fetch alice remotes/origin/master master alice-interests rainbows unicorns hates

Slide 146

Slide 146 text

$ git fetch remote: Counting objects: 3, done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), done. From https://github.com/xxx/talk-git 712cc39..ca980cb master -> origin/master //Same as $ git fetch origin master:master // (remote remote-source:local-destination) $ git checkout git fetch alice remotes/origin/master master alice-interests rainbows unicorns hates

Slide 147

Slide 147 text

$ git fetch remote: Counting objects: 3, done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), done. From https://github.com/xxx/talk-git 712cc39..ca980cb master -> origin/master //Same as $ git fetch origin master:master // (remote remote-source:local-destination) $ git checkout Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded. (use "git pull" to update your local branch) git fetch alice remotes/origin/master master alice-interests rainbows unicorns hates

Slide 148

Slide 148 text

git fetch .git/refs/remotes/origin/alice-interests <- points to position of branch HEAD .git/logs/refs/remotes/origin/alice-interests <- tracks movement of HEAD over time .git/objects/??/??? <- new commits!

Slide 149

Slide 149 text

git fetch downloads your changes from a remote repository

Slide 150

Slide 150 text

git merge NAME git-merge - Join two or more development histories together SYNOPSIS git merge [--no-ff] SUMMARY Combines code from two separate branches fast-forward moves the branch pointer 3 way merge combines divergent files --no-ff prevents fast forward merges

Slide 151

Slide 151 text

$ git checkout Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded. (use "git pull" to update your local branch) $ git merge origin/master git merge alice remotes/origin/master master alice-interests rainbows unicorns hates

Slide 152

Slide 152 text

$ git checkout Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded. (use "git pull" to update your local branch) $ git merge origin/master Updating 712cc39..ca980cb Fast-forward alice.txt | 2 ++ 1 file changed, 2 insertions(+) git merge alice remotes/origin/master alice-interests rainbows unicorns hates master

Slide 153

Slide 153 text

a fast-forward merge moves the branch pointer ‘forward’ to a subsequent commit ...No need to create new commits

Slide 154

Slide 154 text

$ git diff alice-interests git merge alice remotes/origin/master alice-interests rainbows unicorns hates master

Slide 155

Slide 155 text

$ git diff alice-interests diff --git a/alice.txt b/alice.txt index 3da64f6..d30e97a 100644 --- a/alice.txt +++ b/alice.txt @@ -1,5 +1,3 @@ Hi!, I’m Alice. -I like rainbows. - -I also like unicorns. +I hate merge conflicts git merge alice remotes/origin/master alice-interests rainbows unicorns hates master

Slide 156

Slide 156 text

$ git merge alice-interests alice remotes/origin/master alice-interests rainbows unicorns hates master git merge

Slide 157

Slide 157 text

$ git merge alice-interests Auto-merging alice.txt CONFLICT (content): Merge conflict in alice.txt Automatic merge failed; fix conflicts and then commit the result. alice remotes/origin/master alice-interests rainbows unicorns hates master git merge

Slide 158

Slide 158 text

$ git merge alice-interests Auto-merging alice.txt CONFLICT (content): Merge conflict in alice.txt Automatic merge failed; fix conflicts and then commit the result. $ vim alice.txt alice remotes/origin/master alice-interests rainbows unicorns hates master git merge

Slide 159

Slide 159 text

$ git merge alice-interests Auto-merging alice.txt CONFLICT (content): Merge conflict in alice.txt Automatic merge failed; fix conflicts and then commit the result. $ vim alice.txt Hi!, I’m Alice. <<<<<<< HEAD I hate merge conflicts ======= I like rainbows. I also like unicorns. >>>>>>> alice-interests alice remotes/origin/master alice-interests rainbows unicorns hates master git merge (3-way)

Slide 160

Slide 160 text

$ git merge alice-interests Auto-merging alice.txt CONFLICT (content): Merge conflict in alice.txt Automatic merge failed; fix conflicts and then commit the result. $ vim alice.txt Hi!, I’m Alice. I hate merge conflicts. I like rainbows. I also like unicorns. alice remotes/origin/master alice-interests rainbows unicorns hates master git merge (3-way)

Slide 161

Slide 161 text

$ git add alice.txt alice remotes/origin/master alice-interests rainbows unicorns hates master git merge (3-way)

Slide 162

Slide 162 text

$ git add alice.txt $ git commit alice remotes/origin/master alice-interests rainbows unicorns hates master git merge (3-way)

Slide 163

Slide 163 text

$ git add alice.txt $ git commit Merge branch 'alice-interests' # Conflicts: # alice.txt # # It looks like you may be committing a merge. # If this is not correct, please remove the file # .git/MERGE_HEAD # and try again. # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch master # Your branch is up-to-date with 'origin/master'. # # All conflicts fixed but you are still merging. # # Changes to be committed: # modified: alice.txt # git merge (3-way) alice remotes/origin/master alice-interests rainbows unicorns hates master

Slide 164

Slide 164 text

$ git add alice.txt $ git commit [master 257b18b] Merge branch 'alice-interests' git merge (3-way) alice remotes/origin/master alice-interests rainbows unicorns hates master merge

Slide 165

Slide 165 text

If we cannot fast forward, git will 3-way merge two branch tips with a common base ...Creating a new commit

Slide 166

Slide 166 text

No content

Slide 167

Slide 167 text

git merge .git/refs/heads/alice-interests <- points to position of branch HEAD .git/logs/refs/heads/alice-interests <- tracks movement of HEAD over time .git/objects/??/?? <- new commits! .git/MERGE_HEAD also changes during this process

Slide 168

Slide 168 text

Merging commits in as a single package http://nvie.com/posts/a-successful-git-branching-model/

Slide 169

Slide 169 text

git merge combines changes between two branches ...preserving history

Slide 170

Slide 170 text

git cherry-pick NAME git-cherry-pick - Apply the changes introduced by some existing commits SYNOPSIS git cherry-pick SUMMARY Applies a single commit to the HEAD of your branch

Slide 171

Slide 171 text

$ git reset --hard origin/master HEAD is now at 123b993 Note that Alice hates merge conflicts git cherry-pick alice remotes/origin/master alice-interests rainbows unicorns hates master

Slide 172

Slide 172 text

$ git checkout alice-interests Switched to branch 'alice-interests' git cherry-pick alice remotes/origin/master alice-interests rainbows unicorns hates master

Slide 173

Slide 173 text

$ git checkout alice-interests Switched to branch 'alice-interests' $ git checkout HEAD~1 git cherry-pick alice remotes/origin/master alice-interests rainbows unicorns hates master

Slide 174

Slide 174 text

$ git checkout alice-interests Switched to branch 'alice-interests' $ git checkout HEAD~1 Note: checking out 'HEAD~1'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b HEAD is now at 1593781... Note that Alice likes rainbows. //note this is the same as HEAD^ git cherry-pick alice remotes/origin/master alice-interests rainbows unicorns hates master

Slide 175

Slide 175 text

$ git checkout alice-interests Switched to branch 'alice-interests' $ git checkout HEAD~1 Note: checking out 'HEAD~1'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b HEAD is now at 1593781... Note that Alice likes rainbows. //note this is the same as HEAD^ $ git tag rainbows git cherry-pick alice remotes/origin/master alice-interests rainbows unicorns hates master

Slide 176

Slide 176 text

$ git checkout alice-interests Switched to branch 'alice-interests' $ git checkout HEAD~1 Note: checking out 'HEAD~1'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b HEAD is now at 1593781... Note that Alice likes rainbows. //note this is the same as HEAD^ $ git tag rainbows git cherry-pick alice remotes/origin/master alice-interests rainbows unicorns hates master rainbows

Slide 177

Slide 177 text

$ git checkout alice-interests Switched to branch 'alice-interests' $ git checkout HEAD~1 Note: checking out 'HEAD~1'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b HEAD is now at 1593781... Note that Alice likes rainbows. //note this is the same as HEAD^ $ git tag rainbows $ git checkout master git cherry-pick alice remotes/origin/master alice-interests rainbows unicorns hates master rainbows

Slide 178

Slide 178 text

$ git checkout alice-interests Switched to branch 'alice-interests' $ git checkout HEAD~1 Note: checking out 'HEAD~1'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b HEAD is now at 1593781... Note that Alice likes rainbows. //note this is the same as HEAD^ $ git tag rainbows $ git checkout master Your branch is up-to-date with 'origin/master'. git cherry-pick alice remotes/origin/master alice-interests rainbows unicorns hates master rainbows

Slide 179

Slide 179 text

$ git cherry-pick rainbows git cherry-pick alice remotes/origin/master alice-interests rainbows unicorns hates master rainbows

Slide 180

Slide 180 text

$ git cherry-pick rainbows error: could not apply 1593781... Note that Alice likes rainbows. hint: after resolving the conflicts, mark the corrected paths hint: with 'git add ' or 'git rm ' hint: and commit the result with 'git commit' git cherry-pick alice remotes/origin/master alice-interests rainbows unicorns hates master rainbows

Slide 181

Slide 181 text

$ vim alice.txt Hi!, I’m Alice. <<<<<<< HEAD I hate merge conflicts ======= I like rainbows. >>>>>>> 1593781... Note that Alice likes rainbows. git cherry-pick alice remotes/origin/master alice-interests rainbows unicorns hates master rainbows

Slide 182

Slide 182 text

$ vim alice.txt Hi!, I’m Alice. I hate merge conflicts I like rainbows. git cherry-pick alice remotes/origin/master alice-interests rainbows unicorns hates master rainbows

Slide 183

Slide 183 text

$ git add alice.txt git cherry-pick alice remotes/origin/master alice-interests rainbows unicorns hates master rainbows

Slide 184

Slide 184 text

$ git add alice.txt $ git status git cherry-pick alice remotes/origin/master alice-interests rainbows unicorns hates master rainbows

Slide 185

Slide 185 text

$ git add alice.txt $ git status On branch master Your branch is up-to-date with 'origin/master'. You are currently cherry-picking commit 1593781. (all conflicts fixed: run "git cherry-pick --continue") (use "git cherry-pick --abort" to cancel the cherry-pick operation) Changes to be committed: modified: alice.txt git cherry-pick alice remotes/origin/master alice-interests rainbows unicorns hates master rainbows

Slide 186

Slide 186 text

$ git cherry-pick --continue git cherry-pick alice remotes/origin/master alice-interests rainbows unicorns hates master rainbows

Slide 187

Slide 187 text

$ git cherry-pick --continue Note that Alice likes rainbows. # Conflicts: # alice.txt # # It looks like you may be committing a cherry-pick. # If this is not correct, please remove the file # .git/CHERRY_PICK_HEAD # and try again. # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # Date: Wed Jun 24 15:46:23 2015 +1000 # # On branch master # Your branch is up-to-date with 'origin/master'. # # You are currently cherry-picking commit 1593781. # # Changes to be committed: # modified: alice.txt # git cherry-pick alice remotes/origin/master alice-interests rainbows unicorns hates master rainbows

Slide 188

Slide 188 text

$ git cherry-pick --continue Note that Alice likes rainbows. # Conflicts: # alice.txt # # It looks like you may be committing a cherry-pick. # If this is not correct, please remove the file # .git/CHERRY_PICK_HEAD # and try again. # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # Date: Wed Jun 24 15:46:23 2015 +1000 # # On branch master # Your branch is up-to-date with 'origin/master'. # # You are currently cherry-picking commit 1593781. # # Changes to be committed: # modified: alice.txt # git cherry-pick alice remotes/origin/master alice-interests rainbows unicorns hates master rainbows

Slide 189

Slide 189 text

$ git cherry-pick --continue [master 2bd4e74] Note that Alice likes rainbows. Date: Wed Jun 24 15:46:23 2015 +1000 1 file changed, 1 insertion(+) git cherry-pick alice remotes/origin/master alice-interests rainbows unicorns hates rainbows cherry master

Slide 190

Slide 190 text

git cherry-pick .git/refs/heads/master <- points to position of branch HEAD .git/logs/refs/heads/master <- tracks movement of HEAD over time .git/objects/??/?? <- new commits! .git/CHERRY_PICK_HEAD also changes during this process

Slide 191

Slide 191 text

git cherry-pick http://hades.name/blog/2010/03/03/git-your-friend-not-foe-vol-4-rebasing/

Slide 192

Slide 192 text

one commit = one idea VERY important for cherry-picks

Slide 193

Slide 193 text

git cherry-pick re-writes a commit on top of your branch HEAD

Slide 194

Slide 194 text

git rebase NAME git-rebase - Forward-port local commits to the updated upstream head SYNOPSIS git rebase [--interactive] SUMMARY Fetches, then merges (or rebases with --rebase)

Slide 195

Slide 195 text

$ git reset --hard origin/master HEAD is now at 123b993 Note that Alice hates merge conflicts git rebase alice remotes/origin/master alice-interests rainbows unicorns hates master

Slide 196

Slide 196 text

$ git checkout alice-interests git rebase alice remotes/origin/master alice-interests rainbows unicorns hates master

Slide 197

Slide 197 text

$ git checkout alice-interests Switched to branch 'alice-interests' git rebase alice remotes/origin/master alice-interests rainbows unicorns hates master

Slide 198

Slide 198 text

$ git checkout alice-interests Switched to branch 'alice-interests' $ git checkout -b alice-interests-rebase git rebase alice remotes/origin/master alice-interests rainbows unicorns hates master

Slide 199

Slide 199 text

$ git checkout alice-interests Switched to branch 'alice-interests' $ git checkout -b alice-interests-rebase Switched to a new branch 'alice-interests-rebase' git rebase alice remotes/origin/master alice-interests rainbows unicorns hates master alice-interests-rebase

Slide 200

Slide 200 text

$ git rebase master git rebase alice remotes/origin/master alice-interests rainbows unicorns hates master alice-interests-rebase

Slide 201

Slide 201 text

$ git rebase master git rebase alice remotes/origin/master alice-interests rainbows unicorns hates master alice-interests-rebase

Slide 202

Slide 202 text

$ git rebase master First, rewinding head to replay your work on top of it... git rebase alice remotes/origin/master alice-interests rainbows unicorns hates master alice-interests-rebase

Slide 203

Slide 203 text

$ git rebase master First, rewinding head to replay your work on top of it… Applying: Note that Alice likes rainbows. git rebase alice remotes/origin/master alice-interests rainbows unicorns hates master alice-interests-rebase

Slide 204

Slide 204 text

$ git rebase master First, rewinding head to replay your work on top of it… Applying: Note that Alice likes rainbows. Using index info to reconstruct a base tree... M alice.txt Falling back to patching base and 3-way merge... Auto-merging alice.txt CONFLICT (content): Merge conflict in alice.txt Failed to merge in the changes. Patch failed at 0001 Note that Alice likes rainbows. The copy of the patch that failed is found in: /xxx/talk-git/.git/rebase-apply/patch When you have resolved this problem, run "git rebase --continue". If you prefer to skip this patch, run "git rebase --skip" instead. To check out the original branch and stop rebasing, run "git rebase --abort". git rebase alice remotes/origin/master alice-interests rainbows unicorns hates master alice-interests-rebase

Slide 205

Slide 205 text

$ vim alice.txt Hi!, I’m Alice. <<<<<<< HEAD I hate merge conflicts ======= I like rainbows. >>>>>>> Note that Alice likes rainbows. git rebase alice remotes/origin/master alice-interests rainbows unicorns hates master alice-interests-rebase

Slide 206

Slide 206 text

$ vim alice.txt Hi!, I’m Alice. I hate merge conflicts I like rainbows. git rebase alice remotes/origin/master alice-interests rainbows unicorns hates master alice-interests-rebase

Slide 207

Slide 207 text

$ vim alice.txt Hi!, I’m Alice. I hate merge conflicts I like rainbows. $ git add . git rebase alice remotes/origin/master alice-interests rainbows unicorns hates master alice-interests-rebase

Slide 208

Slide 208 text

$ git rebase --continue git rebase alice remotes/origin/master alice-interests rainbows unicorns hates master alice-interests-rebase

Slide 209

Slide 209 text

$ git rebase --continue Applying: Note that Alice likes rainbows. git rebase alice remotes/origin/master alice-interests rainbows unicorns hates master alice-interests-rebase

Slide 210

Slide 210 text

$ git rebase --continue Applying: Note that Alice likes rainbows. Applying: Note that alice also likes unicorns git rebase alice remotes/origin/master alice-interests rainbows unicorns hates master alice-interests-rebase rainbows-rb

Slide 211

Slide 211 text

$ git rebase --continue Applying: Note that Alice likes rainbows. Applying: Note that alice also likes unicorns Using index info to reconstruct a base tree... M alice.txt git rebase alice remotes/origin/master alice-interests rainbows unicorns hates master alice-interests-rebase rainbows-rb

Slide 212

Slide 212 text

$ git rebase --continue Applying: Note that Alice likes rainbows. Applying: Note that alice also likes unicorns Using index info to reconstruct a base tree... M alice.txt Falling back to patching base and 3-way merge... git rebase alice remotes/origin/master alice-interests rainbows unicorns hates master alice-interests-rebase rainbows-rb

Slide 213

Slide 213 text

$ git rebase --continue Applying: Note that Alice likes rainbows. Applying: Note that alice also likes unicorns Using index info to reconstruct a base tree... M alice.txt Falling back to patching base and 3-way merge... Auto-merging alice.txt git rebase alice remotes/origin/master alice-interests rainbows unicorns hates master alice-interests-rebase rainbows-rb

Slide 214

Slide 214 text

$ git rebase --continue Applying: Note that Alice likes rainbows. Applying: Note that alice also likes unicorns Using index info to reconstruct a base tree... M alice.txt Falling back to patching base and 3-way merge... Auto-merging alice.txt $ git rebase alice remotes/origin/master alice-interests rainbows unicorns hates master rainbows-rb unicorns alice-interests-rebase

Slide 215

Slide 215 text

git rebase .git/refs/heads/master <- points to position of branch HEAD .git/logs/refs/heads/master <- tracks movement of HEAD over time .git/objects/??/?? <- new commits! .git/REBASE_HEAD also changes during this process

Slide 216

Slide 216 text

git rebase http://hades.name/blog/2010/03/03/git-your-friend-not-foe-vol-4-rebasing/

Slide 217

Slide 217 text

git rebase be like:

Slide 218

Slide 218 text

Rebase disclaimer ✪ Re-writing history ✭ Duplicating commits - may break some git operations ✮ git branch --merged, --contains etc. ✮ git bisect ✭ Not for public branches (you will break peoples trees!) ✮ force pushing makes bunny cry! ✭ Tags will be incorrect (they never move) ✪ New base ✭ Integration issues may not be apparent ✭ Reverted code gets thrown away (fast-forwarded) http://paul.stadig.name/2010/12/thou-shalt-not-lie-git-rebase-ammend.html

Slide 219

Slide 219 text

git pull NAME Fetch from and integrate with another repository or a local branch SYNOPSIS git pull [options] [ [...]] SUMMARY Fetches, then merges (or rebases with --rebase)

Slide 220

Slide 220 text

git pull http://hades.name/blog/2010/03/03/git-your-friend-not-foe-vol-4-rebasing/

Slide 221

Slide 221 text

git pull is a shorthand for git fetch && git merge (or git rebase with --rebase)

Slide 222

Slide 222 text

Centralised Workflow https://www.atlassian.com/git/tutorials/merging-vs-rebasing/workflow-walkthrough

Slide 223

Slide 223 text

Semi-Centralised Workflow http://nvie.com/posts/a-successful-git-branching-model/

Slide 224

Slide 224 text

Forking workflow (github) https://speakerdeck.com/holman/how-github-uses-github-to-build-github

Slide 225

Slide 225 text

✪ Easier to revert in an emergency ✪ Easier to track down bugs ✪ Easier to read! Linear vs Non-Linear source tree

Slide 226

Slide 226 text

Playing nice with others ...But what if it breaks?

Slide 227

Slide 227 text

Restore previous work ✪ Go back in time. Undo mistakes. ✭ stash ✭ reset ✭ revert

Slide 228

Slide 228 text

git stash NAME git-stash - Stash the changes in a dirty working directory away SYNOPSIS git stash git stash pop SUMMARY stash hides your work tree stash pop brings it back

Slide 229

Slide 229 text

git stash hides your work tree for later

Slide 230

Slide 230 text

git reset NAME git-reset - Reset current HEAD to the specified state SYNOPSIS git reset (--hard | --soft | --mixed) [] SUMMARY --hard moves HEAD, throws away work tree --soft moves HEAD, stages work tree (index) --mixed moves HEAD, unstages work tree HEAD == BRANCH

Slide 231

Slide 231 text

git reset moves your work tree to another commit

Slide 232

Slide 232 text

git revert NAME git-revert - Revert some existing commits SYNOPSIS git revert [-m parent#] SUMMARY Writes a new commit, negating the old one. Can undo an entire feature branch by reverting a merge commit ONE COMMIT = ONE IDEA. VERY IMPORTANT. merge --no-ff also important (so you can revert all changes in branch)

Slide 233

Slide 233 text

Revert pitfalls ✪ Blackballing commits ✭ Revert “means” I do not want to release this ✭ Break subsequent rebases/merges ✮ git will avoid duplication of existing commits ✮ Must revert the revert commit ✭ May break some analysis tools ✭ Harder to read history ✭ Integration issues may not be apparent http://paul.stadig.name/2010/12/thou-shalt-not-lie-git-rebase-ammend.html

Slide 234

Slide 234 text

git revert makes a new commit, negating the old one

Slide 235

Slide 235 text

Restore previous work ...Is that it?

Slide 236

Slide 236 text

Awesome stuff ✪ Archaelogy ✪ Tools ✪ Automation ✪ Visualisation

Slide 237

Slide 237 text

Archaeology

Slide 238

Slide 238 text

git log is a history of changes

Slide 239

Slide 239 text

git blame http://bast.fr/talks/git/archaeology/#4 For vim users -> https://github.com/tpope/vim-fugitive

Slide 240

Slide 240 text

git show $ git show 741600aaf5ba3c8f9d7b78b5082370141a2a4632 commit 741600aaf5ba3c8f9d7b78b5082370141a2a4632 Merge: 123b993 047fc66 Author: xxx Date: Wed Jun 24 21:10:11 2015 +1000 Merge branch 'alice-interests' diff --cc alice.txt index d30e97a,3da64f6..64edcef --- a/alice.txt +++ b/alice.txt @@@ -1,3 -1,5 +1,5 @@@ Hi!, I’m Alice. - I hate merge conflicts ++I hate merge conflicts. + I like rainbows. - -I also like unicorns. ++I also like unicorns. http://www.justinweiss.com/blog/2015/03/24/go-beyond-the-easy-fix-with-code-archaeology/

Slide 241

Slide 241 text

git cat-file $ cat .git/refs/heads/merged 741600aaf5ba3c8f9d7b78b5082370141a2a4632 $ git cat-file -p 741600aaf5ba3c8f9d7b78b5082370141a2a4632 tree 9a286e419d26c301178738c752e85a5cbf17cbf2 parent 123b9930155cc4178daf5e04c770e33c30fd2f32 parent 047fc663da7735d5505873756c02ad0414e88804 author xxx 1435144211 +1000 committer xxx 1435144211 +1000 Merge branch 'alice-interests' $ git cat-file -p 9a286e419d26c301178738c752e85a5cbf17cbf2 100644 blob 9fcb792aad6767c2e7346e1e41391761bc71ceb5 .gitmodules 100644 blob 47dbdf0659a968efffdd743224af011882db2e2b README.md 100644 blob 64edcef09c4acbf7763589a68ce6c77f54d11d42 alice.txt 160000 commit 7c5ad9134934288d364ec5befd1f293f12d760f3 git-bisect-demo $ git cat-file -p 64edcef09c4acbf7763589a68ce6c77f54d11d42 Hi!, I’m Alice. I hate merge conflicts. I like rainbows.

Slide 242

Slide 242 text

git reflog NAME git-reflog - Manage reflog information SYNOPSIS git reflog SUMMARY Shows a log of commits you have switched to while working

Slide 243

Slide 243 text

git reflog $ git reflog 123b993 HEAD@{0}: checkout: moving from alice-interests-rebase to master 32d29b9 HEAD@{1}: rebase finished: returning to refs/heads/alice-interests-rebase 32d29b9 HEAD@{2}: rebase: Note that alice also likes unicorns a06280e HEAD@{3}: rebase: Note that Alice likes rainbows. 741600a HEAD@{13}: checkout: moving from master to merge 70fc2b6 HEAD@{16}: commit (cherry-pick): Note that Alice likes rainbows. 1593781 HEAD@{34}: checkout: moving from alice-interests to HEAD~1 047fc66 HEAD@{36}: checkout: moving from master to alice-interests 123b993 HEAD@{38}: reset: moving to origin/master 257b18b HEAD@{42}: commit (merge): Merge branch 'alice-interests' ca980cb HEAD@{43}: merge origin/master: Fast-forward 712cc39 HEAD@{48}: checkout: moving from alice-interests to master 047fc66 HEAD@{49}: commit: Note that alice also likes unicorns fcd5644 HEAD@{52}: commit: Note that Alice likes rainbows. b815e8e HEAD@{59}: commit: Add Alice's interests 712cc39 HEAD@{60}: commit: Add alice.txt 36d64b1 HEAD@{61}: commit: Add git-bisect-demo as a submodule cde833e HEAD@{62}: reset: moving to cde833ef40e01cc2393cf65b2f12bcc0409d7332 24c8660 HEAD@{63}: commit: Add git-bisect-demo as a submodule cde833e HEAD@{64}: clone: from https://github.com/xxx/talk-git (excerpt)

Slide 244

Slide 244 text

git reflog is a history of your history

Slide 245

Slide 245 text

Tools

Slide 246

Slide 246 text

tig https://github.com/jonas/tig

Slide 247

Slide 247 text

ungit https://github.com/FredrikNoren/ungit

Slide 248

Slide 248 text

In-IDE diff (Netbeans) (sublime, vim etc. all have similar)

Slide 249

Slide 249 text

In-IDE history (Netbeans, others) http://bast.fr/talks/git/archaeology/#4

Slide 250

Slide 250 text

gitflow http://jeffkreeftmeijer.com/ 2010/why-arent-you-using -git-flow/

Slide 251

Slide 251 text

Centralised Workflow https://www.atlassian.com/git/tutorials/merging-vs-rebasing/workflow-walkthrough

Slide 252

Slide 252 text

Arcanist - cmdline Phab!

Slide 253

Slide 253 text

Github pull requests https://help.github.com/articles/using-pull-requests/

Slide 254

Slide 254 text

Automate. Everything.

Slide 255

Slide 255 text

Hooks! https://www.atlassian.com/git/tutorials/git-hooks/conceptual-overview http://githooks.com/

Slide 256

Slide 256 text

.git/hooks/pre-commit #!/usr/bin/php /dev/null', $output, $return); $against = $return == 0 ? 'HEAD' : '4b825dc642cb6eb9a060e54bf8d69288fbee4904'; exec("git diff-index --cached --name-only {$against}", $output); $filename_pattern = '/\.php$/'; $exit_status = 0; foreach ($output as $file) { if (!preg_match($filename_pattern, $file) || !file_exists($file)) { // don't check files that aren't PHP continue; } $lint_output = array(); exec("php -l " . escapeshellarg($file), $lint_output, $return); if ($return == 0) { continue; } echo implode("\n", $lint_output), "\n"; $exit_status = 1; } exit($exit_status); NO MORE SYNTAX ERRORS

Slide 257

Slide 257 text

.git/hooks/post-receive #!/bin/sh #Update GIT_WORK_TREE=/YOUR/WEB/ROOT echo "********************************************" echo "Post receive hook - Updating:" echo $GIT_WORK_TREE echo "********************************************" sudo rm -Rf $GIT_WORK_TREE sudo mkdir $GIT_WORK_TREE sudo chown -R git $GIT_WORK_TREE GIT_WORK_TREE=$GIT_WORK_TREE git checkout master -f #set perms sudo chown -R www-data $GIT_WORK_TREE sudo chgrp -R www-data $GIT_WORK_TREE echo "********************************************" echo "Updated:" echo $GIT_WORK_TREE echo "********************************************" CI/CD IN THE GHETTO https://www.digitalocean.com/community/tutorials/how-to-use-git-hooks-to-automate- development-and-deployment-tasks

Slide 258

Slide 258 text

git is commandline - scripts! ✪ All the tools pretty much trigger off git operations ✪ git alias or roll your own shell scripts to save typing ✭ checkout master && git pull --rebase && arc patch $1 ✭ git add && clear && git status ✭ git diff --cached && git status && echo ---- && git commit ✪ Piping output into other scripts / commands ✭ Prune old branches ✮ checkout master && git branch --merged | xargs git branch -d ✭ Parse logs ✭ Automated bug hunting with git bisect

Slide 259

Slide 259 text

git bisect NAME git-bisect - Find by binary search the change that introduced a bug SYNOPSIS git bisect start git bisect bad git bisect good git bisect run (scripted) SUMMARY Searches through your commits, allowing you to eliminate ‘good’ commits until you find the ‘bad’ commit that introduced a bug. https://github.com/agross/git-bisect-demo (also a module in talk source)

Slide 260

Slide 260 text

Visualisation

Slide 261

Slide 261 text

Github shinies https://github.com/php/php-src/graphs/commit-activity

Slide 262

Slide 262 text

Visualisation - Git by a Bus http://product.hubspot.com/blog/bid/57694/Git-by-a-Bus

Slide 263

Slide 263 text

Visualisation - git-big-picture https://github.com/esc/git-big-picture

Slide 264

Slide 264 text

Visualisation - Gource (Symfony 2) https://code.google.com/p/gource/wiki/Controls https://www.youtube.com/watch?v=K6OQ0r5EVWA

Slide 265

Slide 265 text

MOAR Links! ✪ General ✭ http://git-scm.com/doc ✭ https://www.atlassian.com/git/tutorials/advanced-overview ✭ https://speakerdeck.com/holman/git-and-github-secrets ✭ http://zrusin.blogspot.com.au/2007/09/git-cheat-sheet.html ✪ Rebasing / Workflow ✭ https://www.atlassian.com/git/articles/git-team-workflows-merge-or-rebase/ ✪ Tutorials ✭ http://pcottle.github.io/learnGitBranching/ ✭ http://gitready.com/

Slide 266

Slide 266 text

Was else is awesome? ...Ask me questions. :)