Slide 1

Slide 1 text

git for beginners Mike McQuaid

Slide 2

Slide 2 text

me

Slide 3

Slide 3 text

@MikeMcQuaid mike@mikemcquaid.com http://mikemcquaid.com

Slide 4

Slide 4 text

install create commit history remote fix branch rewrite tools help

Slide 5

Slide 5 text

install

Slide 6

Slide 6 text

 Xcode 4 or brew install git

Slide 7

Slide 7 text

apt-get install git-core

Slide 8

Slide 8 text

 msysgit

Slide 9

Slide 9 text

git config

Slide 10

Slide 10 text

$ git config --global user.name "Your Name" $ git config --global user.email me@example.com

Slide 11

Slide 11 text

create

Slide 12

Slide 12 text

git init

Slide 13

Slide 13 text

$ git init test Initialized empty Git repository in /Users/you/test/.git/

Slide 14

Slide 14 text

git status

Slide 15

Slide 15 text

$ git status # On branch master # # Initial commit # nothing to commit (create/copy files and use "git add" to track)

Slide 16

Slide 16 text

commit

Slide 17

Slide 17 text

git add

Slide 18

Slide 18 text

$ git status # On branch master # # Initial commit # # Untracked files: # (use "git add ..." to include in what will be committed) # # ReadMe.txt nothing added to commit but untracked files present (use "git add" to track)

Slide 19

Slide 19 text

$ git add ReadMe.txt

Slide 20

Slide 20 text

$ git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached ..." to unstage) # # new file: ReadMe.txt #

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

git commit

Slide 23

Slide 23 text

$ git commit -m "Initial commit" [master (root-commit) ba9d588] Initial commit 0 files changed create mode 100644 ReadMe.txt

Slide 24

Slide 24 text

history

Slide 25

Slide 25 text

git log

Slide 26

Slide 26 text

$ git log commit ba9d5884d2ea8946e9bf3b6c151d61c8cd952cb1 Author: Your Name Date: Mon Feb 27 21:32:41 2012 +0000 Initial commit

Slide 27

Slide 27 text

gitx gitk

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

git diff

Slide 30

Slide 30 text

$ git status # On branch master # Changes not staged for commit: # (use "git add ..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working directory) # # modified: ReadMe.txt # no changes added to commit (use "git add" and/or "git commit -a")

Slide 31

Slide 31 text

$ git diff diff --git a/ReadMe.txt b/ReadMe.txt index e69de29..cd08755 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -0,0 +1 @@ +Hello world!

Slide 32

Slide 32 text

$ git status # On branch master # Changes not staged for commit: # (use "git add ..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working directory) # # modified: ReadMe.txt # no changes added to commit (use "git add" and/or "git commit -a")

Slide 33

Slide 33 text

$ git add ReadMe.txt

Slide 34

Slide 34 text

$ git diff

Slide 35

Slide 35 text

$ git diff --staged diff --git a/ReadMe.txt b/ReadMe.txt index e69de29..cd08755 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -0,0 +1 @@ +Hello world!

Slide 36

Slide 36 text

$ git diff master diff --git a/ReadMe.txt b/ReadMe.txt index e69de29..cd08755 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -0,0 +1 @@ +Hello world!

Slide 37

Slide 37 text

$ git diff HEAD diff --git a/ReadMe.txt b/ReadMe.txt index e69de29..cd08755 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -0,0 +1 @@ +Hello world!

Slide 38

Slide 38 text

$ git commit -m "Add ReadMe" [master ffc8706] Add ReadMe 1 file changed, 1 insertion(+)

Slide 39

Slide 39 text

$ git log commit ffc8706e41abb387993c294d7d46070a4bbd76ba Author: Your Name Date: Mon Feb 27 21:38:38 2012 +0000 Add ReadMe commit ba9d5884d2ea8946e9bf3b6c151d61c8cd952cb1 Author: Your Name Date: Mon Feb 27 21:32:41 2012 +0000 Initial commit

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

remote

Slide 42

Slide 42 text

git clone

Slide 43

Slide 43 text

$ git clone git://github.com/mxcl/homebrew.git Cloning into 'homebrew'... remote: Counting objects: 58026, done. remote: Compressing objects: 100% (24408/24408), done. remote: Total 58026 (delta 37820), reused 50148 (delta 32895) Receiving objects: 100% (58026/58026), 8.69 MiB | 59 KiB/s, done. Resolving deltas: 100% (37820/37820), done.

Slide 44

Slide 44 text

$ git log --stat 29d85 commit 29d85578e75170a6c0eaebda4d701b46f1acf446 Author: Max Howell Date: Thu May 21 00:04:11 2009 +0100 I'll start with a rare Belgian yeast and Sussex hops README | 137 ++++++++++++++++++++++++++ 1 file changed, 137 insertions(+)

Slide 45

Slide 45 text

git push

Slide 46

Slide 46 text

$ git push Counting objects: 9, done. Delta compression using up to 8 threads. Compressing objects: 100% (5/5), done. Writing objects: 100% (5/5), 485 bytes, done. Total 5 (delta 4), reused 0 (delta 0) To git@github.com:mxcl/homebrew.git 4ab1f7a..753dde9 master -> master

Slide 47

Slide 47 text

git fetch

Slide 48

Slide 48 text

$ git fetch remote: Counting objects: 140, done. remote: Compressing objects: 100% (65/65), done. remote: Total 93 (delta 79), reused 42 (delta 28) Unpacking objects: 100% (93/93), done. From git://github.com/mxcl/homebrew 753dde9..3c180ba master -> origin/master

Slide 49

Slide 49 text

git pull

Slide 50

Slide 50 text

git pull = git fetch && git merge

Slide 51

Slide 51 text

git pull --rebase = git fetch && git rebase

Slide 52

Slide 52 text

$ git pull remote: Counting objects: 9, done. remote: Compressing objects: 100% (1/1), done. remote: Total 5 (delta 4), reused 5 (delta 4) Unpacking objects: 100% (5/5), done. From git://github.com/mxcl/homebrew 4ab1f7a..753dde9 master -> origin/master First, rewinding head to replay your work on top of it... Fast-forwarded master to 753dde9c2cf66848183f3f787f8501dbf5a7e28f.

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

fix

Slide 55

Slide 55 text

git mv

Slide 56

Slide 56 text

$ git mv ReadMe.txt ReadMe.md

Slide 57

Slide 57 text

$ git status # On branch master # Changes to be committed: # (use "git reset HEAD ..." to unstage) # # renamed: ReadMe.txt -> ReadMe.md #

Slide 58

Slide 58 text

$ git commit -m "Markdown ReadMe" [master a385898] Markdown ReadMe 1 file changed, 0 insertions(+), 0 deletions(-) rename ReadMe.txt => ReadMe.md (100%)

Slide 59

Slide 59 text

git rm

Slide 60

Slide 60 text

$ git rm ReadMe.md rm 'ReadMe.md'

Slide 61

Slide 61 text

$ git status # On branch master # Changes to be committed: # (use "git reset HEAD ..." to unstage) # # deleted: ReadMe.md #

Slide 62

Slide 62 text

$ git commit -m "Delete ReadMe" [master d84ef55] Delete ReadMe 1 file changed, 1 deletion(-) delete mode 100644 ReadMe.md

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

git revert

Slide 65

Slide 65 text

$ git revert d84ef55 [master f286fb4] Revert "Delete ReadMe" 1 file changed, 1 insertion(+) create mode 100644 ReadMe.md

Slide 66

Slide 66 text

$ git log HEAD~2..HEAD commit f286fb49f622b1292e8560b5c02bb8a33a115221 Author: Your Name Date: Mon Feb 27 21:49:16 2012 +0000 Revert "Delete ReadMe" This reverts commit d84ef5556bdbd952030d19449ac6cf4af7a1b975. commit d84ef5556bdbd952030d19449ac6cf4af7a1b975 Author: Your Name Date: Mon Feb 27 21:48:53 2012 +0000 Delete ReadMe

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

git clean

Slide 69

Slide 69 text

$ git status # On branch master # Untracked files: # (use "git add ..." to include in what will be committed) # # ReadMe.old nothing added to commit but untracked files present (use "git add" to track)

Slide 70

Slide 70 text

$ git clean -f Removing ReadMe.old

Slide 71

Slide 71 text

$ git status # On branch master nothing to commit (working directory clean)

Slide 72

Slide 72 text

branch

Slide 73

Slide 73 text

git branch

Slide 74

Slide 74 text

$ git branch * master

Slide 75

Slide 75 text

$ git branch testing

Slide 76

Slide 76 text

$ git branch * master testing

Slide 77

Slide 77 text

git checkout

Slide 78

Slide 78 text

$ git checkout testing Switched to branch 'testing'

Slide 79

Slide 79 text

$ git branch master * testing

Slide 80

Slide 80 text

$ git add ReadMe.md

Slide 81

Slide 81 text

$ git commit -m "Add header" [testing 85200e2] Add header 1 file changed, 1 insertion(+)

Slide 82

Slide 82 text

git merge

Slide 83

Slide 83 text

$ git checkout master Switched to branch 'master'

Slide 84

Slide 84 text

$ git diff testing diff --git a/ReadMe.md b/ReadMe.md index 717157d..cd08755 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -1,2 +1 @@ Hello world! -============

Slide 85

Slide 85 text

$ git add License.md

Slide 86

Slide 86 text

$ git commit -m "Add license" [master 8e7d2b6] Add license 1 file changed, 1 insertion(+) create mode 100644 License.md

Slide 87

Slide 87 text

$ git diff testing diff --git a/License.md b/License.md new file mode 100644 index 0000000..85265b0 --- /dev/null +++ b/License.md @@ -0,0 +1 @@ +Public domain diff --git a/ReadMe.md b/ReadMe.md index 717157d..cd08755 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -1,2 +1 @@ Hello world! -============

Slide 88

Slide 88 text

No content

Slide 89

Slide 89 text

$ git merge testing Merge made by the 'recursive' strategy. ReadMe.md | 1 + 1 file changed, 1 insertion(+)

Slide 90

Slide 90 text

No content

Slide 91

Slide 91 text

$ git branch -d testing Deleted branch testing (was 85200e2).

Slide 92

Slide 92 text

No content

Slide 93

Slide 93 text

git tag

Slide 94

Slide 94 text

$ git tag v0.1

Slide 95

Slide 95 text

No content

Slide 96

Slide 96 text

git stash

Slide 97

Slide 97 text

$ git diff diff --git a/License.md b/License.md index 85265b0..a22a2da 100644 --- a/License.md +++ b/License.md @@ -1 +1 @@ -Public domain +MIT

Slide 98

Slide 98 text

$ git stash Saved working directory and index state WIP on master: d13413e Merge branch 'testing' HEAD is now at d13413e Merge branch 'testing'

Slide 99

Slide 99 text

$ git diff

Slide 100

Slide 100 text

No content

Slide 101

Slide 101 text

$ git stash pop # On branch master # Changes not staged for commit: # (use "git add ..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working directory) # # modified: License.md # no changes added to commit (use "git add" and/or "git commit -a") Dropped refs/stash@{0} (a3b0d391ffa40e7483e8c1194c05e628dc13f2fe)

Slide 102

Slide 102 text

$ git diff diff --git a/License.md b/License.md index 85265b0..a22a2da 100644 --- a/License.md +++ b/License.md @@ -1 +1 @@ -Public domain +MIT

Slide 103

Slide 103 text

No content

Slide 104

Slide 104 text

$ git commit -m "Change license" [master 836f9b7] Change license 1 file changed, 1 insertion(+), 1 deletion(-)

Slide 105

Slide 105 text

rewrite

Slide 106

Slide 106 text

git reset

Slide 107

Slide 107 text

No content

Slide 108

Slide 108 text

$ git reset HEAD^ Unstaged changes after reset: M License.md

Slide 109

Slide 109 text

$ git diff diff --git a/License.md b/License.md index 85265b0..a22a2da 100644 --- a/License.md +++ b/License.md @@ -1 +1 @@ -Public domain +MIT

Slide 110

Slide 110 text

No content

Slide 111

Slide 111 text

$ git commit -m "Change license" [master 6459532] Change license 1 file changed, 1 insertion(+), 1 deletion(-)

Slide 112

Slide 112 text

No content

Slide 113

Slide 113 text

$ git reset --hard HEAD^ HEAD is now at d13413e Merge branch 'testing'

Slide 114

Slide 114 text

No content

Slide 115

Slide 115 text

$ git diff

Slide 116

Slide 116 text

git reflog

Slide 117

Slide 117 text

$ git reflog d13413e HEAD@{0}: reset: moving to HEAD^ 6459532 HEAD@{1}: commit: Change license d13413e HEAD@{2}: reset: moving to HEAD^ 836f9b7 HEAD@{3}: commit: Change license d13413e HEAD@{4}: merge testing: Merge made by the 'recursive' strategy.

Slide 118

Slide 118 text

No content

Slide 119

Slide 119 text

$ git reset --hard 6459532 HEAD is now at 6459532 Change license

Slide 120

Slide 120 text

No content

Slide 121

Slide 121 text

git rebase

Slide 122

Slide 122 text

$ git checkout -b testing Switched to a new branch 'testing'

Slide 123

Slide 123 text

$ git reset --hard 85200e2 HEAD is now at 85200e2 Add header

Slide 124

Slide 124 text

$ git add ReadMe.md

Slide 125

Slide 125 text

$ git commit -m "First point" [testing 9fa6296] First point 1 file changed, 1 insertion(+)

Slide 126

Slide 126 text

No content

Slide 127

Slide 127 text

$ git rebase master First, rewinding head to replay your work on top of it... Applying: First point

Slide 128

Slide 128 text

No content

Slide 129

Slide 129 text

tools

Slide 130

Slide 130 text

git describe

Slide 131

Slide 131 text

$ git describe --tags v0.1-2-g18a2fde

Slide 132

Slide 132 text

git blame

Slide 133

Slide 133 text

$ git blame ReadMe.md f286fb49 (Your Name 2012-02-27 21:49:16 +0000 1) Hello world! 85200e28 (Your Name 2012-02-28 14:30:47 +0000 2) ============ 18a2fded (Your Name 2012-02-28 12:03:40 -0500 3) * First point

Slide 134

Slide 134 text

git svn

Slide 135

Slide 135 text

git bisect

Slide 136

Slide 136 text

GitHub

Slide 137

Slide 137 text

git help

Slide 138

Slide 138 text

$ git help diff

Slide 139

Slide 139 text

$ git diff --help

Slide 140

Slide 140 text

http://progit.org http://help.github.com

Slide 141

Slide 141 text

install create commit history remote fix branch rewrite tools help

Slide 142

Slide 142 text

https://github.com/ mikemcquaid/ GitForBeginnersDemo

Slide 143

Slide 143 text

@MikeMcQuaid mike@mikemcquaid.com http://mikemcquaid.com

Slide 144

Slide 144 text

questions?