Slide 1

Slide 1 text

WTF is GIT? a humble talk by Sergey Arkhipov in MERA on 15 Nov 2011 11 Jan 2013

Slide 2

Slide 2 text

WTF is GIT? Agenda 1. What is GIT? 2. GIT vs ClearCase 3. Fully distributed 4. GIT workflow 5. Musthave commands 6. Some tools 7. Credits

Slide 3

Slide 3 text

What is GIT?

Slide 4

Slide 4 text

What is GIT? Git is an open source, distributed version control system designed for speed and efficiency.

Slide 5

Slide 5 text

What is GIT? Came from Linux world 1991-2002 No source code management (tarballs and patches) 2002-2005 Bitkeeper 2005- Git

Slide 6

Slide 6 text

What is GIT? Git is an open source, distributed version control system designed for speed and efficiency.

Slide 7

Slide 7 text

Snapshots, not patches!

Slide 8

Slide 8 text

What is GIT? Snapshots, not patches! Delta storage Snapshot storage

Slide 9

Slide 9 text

What is GIT? Snapshots, not patches! Delta storage C1 spam.py eggs.py build.xml Snapshot storage

Slide 10

Slide 10 text

What is GIT? Snapshots, not patches! Delta storage C1 C2 spam.py eggs.py build.xml Δ 1 Δ 1 Snapshot storage

Slide 11

Slide 11 text

What is GIT? Snapshots, not patches! Delta storage C1 C2 C3 spam.py eggs.py build.xml Δ 1 Δ 1 Δ 2 Δ 2 Snapshot storage

Slide 12

Slide 12 text

What is GIT? Snapshots, not patches! Delta storage C1 C2 C3 C4 spam.py eggs.py build.xml Δ 1 Δ 1 Δ 2 Δ 2 Δ 3 Snapshot storage

Slide 13

Slide 13 text

What is GIT? Snapshots, not patches! Delta storage C1 spam.py eggs.py build.xml Snapshot storage C1 A B C

Slide 14

Slide 14 text

What is GIT? Snapshots, not patches! Delta storage C1 C2 spam.py eggs.py build.xml Δ 1 Δ 1 Snapshot storage C1 C2 A B C A1 C1 B1

Slide 15

Slide 15 text

What is GIT? Snapshots, not patches! Delta storage C1 C2 spam.py eggs.py build.xml Δ 1 Δ 1 Snapshot storage C1 C2 A B C A1 C1 B1

Slide 16

Slide 16 text

What is GIT? Snapshots, not patches! Delta storage C1 C2 C3 spam.py eggs.py build.xml Δ 1 Δ 1 Δ 2 Δ 2 Snapshot storage C1 C2 C3 A B C A1 C1 A2 B2 B1 C2

Slide 17

Slide 17 text

What is GIT? Snapshots, not patches! Delta storage C1 C2 C3 spam.py eggs.py build.xml Δ 1 Δ 1 Δ 2 Δ 2 Snapshot storage C1 C2 C3 A B C A1 C1 A2 B2 B1 C2

Slide 18

Slide 18 text

What is GIT? Snapshots, not patches! Delta storage C1 C2 C3 C4 spam.py eggs.py build.xml Δ 1 Δ 1 Δ 2 Δ 2 Δ 3 Snapshot storage C1 C2 C3 C4 A B C A1 C1 A2 B2 C3 B1 C2 A3 B3

Slide 19

Slide 19 text

What is GIT? Snapshots, not patches! Delta storage C1 C2 C3 C4 spam.py eggs.py build.xml Δ 1 Δ 1 Δ 2 Δ 2 Δ 3 Snapshot storage C1 C2 C3 C4 A B C A1 C1 A2 B2 C3 B1 C2 A3 B3

Slide 20

Slide 20 text

What is GIT? Snapshots, not patches! Delta storage C1 C2 C3 C4 spam.py eggs.py build.xml Δ 1 Δ 1 Δ 2 Δ 2 Δ 3 Snapshot storage C1 C2 C3 C4 A B C A1 C1 A2 B2 C3 B1 C2 A3 B3

Slide 21

Slide 21 text

What is GIT? Snapshots, not patches! Delta storage C1 C2 C3 C4 spam.py eggs.py build.xml Δ 1 Δ 1 Δ 2 Δ 2 Δ 3 Snapshot storage C1 C2 C3 C4 A B C A1 C1 A2 B2 C3 B1 C2 A3 B3

Slide 22

Slide 22 text

What is GIT? Snapshots, not patches! Delta storage C1 C2 C3 C4 spam.py eggs.py build.xml Δ 1 Δ 1 Δ 2 Δ 2 Δ 3 Snapshot storage C1 C2 C3 C4 A B C A1 C1 A2 B2 C3 B1 C2 A3 B3

Slide 23

Slide 23 text

OK. But how is this different to our beloved ClearCase?

Slide 24

Slide 24 text

GIT vs ClearCase

Slide 25

Slide 25 text

GIT vs ClearCase

Slide 26

Slide 26 text

GIT vs ClearCase

Slide 27

Slide 27 text

GIT vs ClearCase

Slide 28

Slide 28 text

GIT vs ClearCase

Slide 29

Slide 29 text

GIT vs ClearCase

Slide 30

Slide 30 text

GIT vs ClearCase

Slide 31

Slide 31 text

GIT vs ClearCase

Slide 32

Slide 32 text

Everything looks great, but…

Slide 33

Slide 33 text

GIT vs ClearCase After 1 year…

Slide 34

Slide 34 text

GIT vs ClearCase

Slide 35

Slide 35 text

GIT vs ClearCase

Slide 36

Slide 36 text

GIT vs ClearCase

Slide 37

Slide 37 text

?

Slide 38

Slide 38 text

GIT vs ClearCase

Slide 39

Slide 39 text

GIT vs ClearCase D1_XXYX_MERA D3_XAYX_MERA D4_XAYX_MERA D3_ZZZ_MERA D1_MAIN_MERA D1_LULZ_MERA D2_LULZ_MERA D3_LULZ_MERA D5_MAIN_MERA D1_WOOT_MERA

Slide 40

Slide 40 text

GIT vs ClearCase D1_XXYX_MERA D3_XAYX_MERA D4_XAYX_MERA D3_ZZZ_MERA D1_MAIN_MERA D1_LULZ_MERA D2_LULZ_MERA D3_LULZ_MERA D5_MAIN_MERA D1_WOOT_MERA D16_SUPA_MERA D1_ARGH_MERA D1_FEAT_MERA D1_KILL_MERA D3_MAIN_MERA

Slide 41

Slide 41 text

GIT vs ClearCase D1_XXYX_MERA D3_XAYX_MERA D4_XAYX_MERA D3_ZZZ_MERA D1_MAIN_MERA D1_LULZ_MERA D2_LULZ_MERA D3_LULZ_MERA D5_MAIN_MERA D1_WOOT_MERA D16_SUPA_MERA D1_ARGH_MERA D1_FEAT_MERA D1_KILL_MERA D3_MAIN_MERA D34_LOLD_MERA D8_EVERYTHING D1_15L5_MERA D8_PHHH_MERA D46_LBL1_MERA D4_1l1l_MERA NBC_SO_NBC SIMPLE_LABEL

Slide 42

Slide 42 text

GIT vs ClearCase D1_XXYX_MERA D3_XAYX_MERA D4_XAYX_MERA D3_ZZZ_MERA D1_MAIN_MERA D1_LULZ_MERA D2_LULZ_MERA D3_LULZ_MERA D5_MAIN_MERA D1_WOOT_MERA D16_SUPA_MERA D1_ARGH_MERA D1_FEAT_MERA D1_KILL_MERA D3_MAIN_MERA D34_LOLD_MERA D8_EVERYTHING D1_15L5_MERA D8_PHHH_MERA D46_LBL1_MERA D4_1l1l_MERA NBC_SO_NBC SIMPLE_LABEL D46_XYZ_MERA D15_XYZ_MERA D18_XYZ_MERA D46_666_MERA TIRED_TO_COPYPASTE D46_HMM_MERA D46_XYZ_MERA D1_WRONG_MERA

Slide 43

Slide 43 text

GIT vs ClearCase D1_XXYX_MERA D3_XAYX_MERA D4_XAYX_MERA D3_ZZZ_MERA D1_MAIN_MERA D1_LULZ_MERA D2_LULZ_MERA D3_LULZ_MERA D5_MAIN_MERA D1_WOOT_MERA D16_SUPA_MERA D1_ARGH_MERA D1_FEAT_MERA D1_KILL_MERA D3_MAIN_MERA D34_LOLD_MERA D8_EVERYTHING D1_15L5_MERA D8_PHHH_MERA D46_LBL1_MERA D4_1l1l_MERA NBC_SO_NBC SIMPLE_LABEL D1_GUYS_ARE_YOU_HAPPY_MERA

Slide 44

Slide 44 text

Are you really happy?

Slide 45

Slide 45 text

GIT vs ClearCase Ordinary ClearCase user

Slide 46

Slide 46 text

GIT vs ClearCase Ordinary GIT user

Slide 47

Slide 47 text

Have you ever realized what your ClearCase view really is?

Slide 48

Slide 48 text

GIT vs ClearCase sum.c subtract.c multiply.c

Slide 49

Slide 49 text

GIT vs ClearCase sum.c subtract.c multiply.c

Slide 50

Slide 50 text

GIT vs ClearCase sum.c subtract.c multiply.c D1_YYY_MERA D2_XXXBLU_MERA D1_ZZZBLU_MERA

Slide 51

Slide 51 text

GIT vs ClearCase sum.c subtract.c multiply.c D2_YYY_MERA D2_XXX_MERA D3_ZZZ_MERA

Slide 52

Slide 52 text

GIT vs ClearCase sum.c subtract.c multiply.c D5_YYY_MERA D12_XXX_MERA D95_ZZZ_MERA

Slide 53

Slide 53 text

Any ideas about evolution of your view?

Slide 54

Slide 54 text

GIT vs ClearCase sum.c subtract.c multiply.c

Slide 55

Slide 55 text

GIT vs ClearCase sum.c subtract.c multiply.c

Slide 56

Slide 56 text

GIT vs ClearCase sum.c subtract.c multiply.c

Slide 57

Slide 57 text

GIT vs ClearCase sum.c subtract.c multiply.c

Slide 58

Slide 58 text

GIT vs ClearCase A3 A1 A2 B1 C2 C1 C3 B2 B3 sum.c subtract.c multiply.c

Slide 59

Slide 59 text

GIT vs ClearCase A1 B1 C1 A2 B2 C2 A3 B3 C3

Slide 60

Slide 60 text

GIT vs ClearCase A1 B1 C1 A2 B2 C2 A3 B3 C3

Slide 61

Slide 61 text

GIT vs ClearCase A1 B1 C1 A2 B2 C2 A3 B3 C3 Snapshot 1 Snapshot 2 Snapshot 3

Slide 62

Slide 62 text

GIT vs ClearCase A1 B1 C1 A2 B2 C2 A3 B3 C3 Snapshot 1 Snapshot 2 Snapshot 3

Slide 63

Slide 63 text

Do not lie yourself. You do not deal with labels. You deal with snapshots.

Slide 64

Slide 64 text

GIT vs ClearCase ● 'Baseline' means 'snapshot' in GIT terms. ● But to deliver you correct snapshots there is the team of masterminds Tieto SWDI who supports label system and makes centralized system redundant. ● Each config spec includes over 9000 different labels to create 1 snapshot.

Slide 65

Slide 65 text

Over 9000 labels to create 1 snapshot

Slide 66

Slide 66 text

GIT vs ClearCase ● And if you want to extend your snapshot, you need to add much more additional rules prettifying Frankensteinish settings. ● Each rule defines how your local copy of ClearCase will have to request information about certain file or diff by network. ● Each operation is performed over the network which causes mortal delays. Everything is very slow. ● Without network you cannot even open file or build something. ● You need to explain your ClearCase by unreadable labels and awkward rules time after time which snapshot you need instead of straight using it.

Slide 67

Slide 67 text

GIT vs ClearCase GIT have no such restrictions by design ● GIT initialy operates snapshots, there is no need in any explicit determining which set of labels you need. ● Everything is local. You may pull changes from master repository and continue your work even in aircraft, with branches and whole development story. You may check earliest version even you lost in Tundra without any internet signs. ● Your repository is your own game. You can develop in any way you want. Just send your changes into central repository at time. ● Operations are really rapid and easy. If you want to select LSV or branch, you do not need to ask central repository for proper set of rules. Just use it!

Slide 68

Slide 68 text

Examples

Slide 69

Slide 69 text

GIT vs ClearCase Choosing baseline ClearCase way Git way $ git checkout BASELINE work $ select_config CPP_DESIGN wait for 2 minutes select latest baseline have a cup of tea exclude components push 'Set' button wait for 2 minutes close application wait for 1 minute work

Slide 70

Slide 70 text

GIT vs ClearCase Branching ClearCase way Git way $ git checkout -b hardcore_branch work $ ct mkbrtype hardcore_branch $ ctedcs Type something like element * CHECKEDOUT element …/hardcore_branch/LATEST element /main/cppdev/LATEST -mkbranch hardcore_branch $ ct co -nc / Work if noone checkedout a file

Slide 71

Slide 71 text

GIT vs ClearCase Building your software ClearCase GIT $ cat ./git_build.sh git checkout BASELINE cd $ cat ./cc_build.sh ct_set_needed_cs -version -baseline cd

Slide 72

Slide 72 text

GIT vs ClearCase Building your software ClearCase GIT $ time -p ./git_build.sh > /dev/null real 58.28 user 21.20 sys 35.14 $ time -p ./cc_build.sh > /dev/null real 1053 user 266 sys 78.72

Slide 73

Slide 73 text

GIT vs ClearCase Building your software ClearCase GIT $ time -p ./git_build.sh > /dev/null real 58.28 user 21.20 sys 35.14 $ time -p ./cc_build.sh > /dev/null real 1053 user 266 sys 78.72 17.5 minutes vs 1 minute!

Slide 74

Slide 74 text

Do you really like ClearCase?

Slide 75

Slide 75 text

Or you just have not used something completely different before?

Slide 76

Slide 76 text

GIT vs ClearCase ● GIT support your actual way of developing software by design. You do not need to juggle tons of labels being in a jail of ClearCase ancient restrictions. ● ClearCase does not allow to use modern convenient ways of developing 'out of box'. It provides you with hardcore methods for hacking it only. ● Everytime you need something from ClearCase, you need to modify your config spec which already contains text with size around a two volumes of 'War and Peace' book instead of telling it what you really want to get. You do not use ClearCase to simplify your job, everytime you appeal to it to get anything.

Slide 77

Slide 77 text

Switcher vocabulary

Slide 78

Slide 78 text

Switcher vocabulary ● Repository — the copy of project ● Commit — fixed snapshot of code base in repository ● Checking out — about populating working tree with the content of a commit: ● Fetch info from repository what files that should be checked out ● Populating working tree with those files ● There is no locking going on anywhere ● git checkout file does not imply any locking ● Checking in – in git you do two things instead: ● Create commit of your change set, store in local repository (git commit) ● Pushing from your local repository to remote repository (git push)

Slide 79

Slide 79 text

Fully distrubuted

Slide 80

Slide 80 text

What is GIT? Git is an open source, distributed version control system designed for speed and efficiency.

Slide 81

Slide 81 text

Fully distributed (almost) everything is local which means ― everything is fast; ― every clone is backup; ― work offline; ― every known remote repo is branch;

Slide 82

Slide 82 text

Fully distributed

Slide 83

Slide 83 text

Fully distributed Ivan's repository Nikolay's repository Natasha's repository Integration repository Trunk repository Central network repositories

Slide 84

Slide 84 text

Fully distributed Ivan's repository Nikolay's repository Natasha's repository Integration repository Trunk repository Central network repositories Designer Designer QA

Slide 85

Slide 85 text

Fully distributed Ivan's repository Nikolay's repository Natasha's repository Integration repository Trunk repository Central network repositories master master master master master

Slide 86

Slide 86 text

Fully distributed Ivan's repository Nikolay's repository Natasha's repository Integration repository Trunk repository Central network repositories master master master master master

Slide 87

Slide 87 text

Fully distributed Ivan's repository Nikolay's repository Natasha's repository Integration repository Trunk repository Central network repositories master master master master master

Slide 88

Slide 88 text

Fully distributed Ivan's repository Nikolay's repository Natasha's repository Integration repository Trunk repository Central network repositories master master master master master feature_x feature_x

Slide 89

Slide 89 text

Fully distributed Ivan's repository Nikolay's repository Natasha's repository Integration repository Trunk repository Central network repositories master master master master master feature_x feature_x test_y

Slide 90

Slide 90 text

Fully distributed Ivan's repository Nikolay's repository Natasha's repository Integration repository Trunk repository Central network repositories master master master master master feature_x feature_x test_y

Slide 91

Slide 91 text

Fully distributed Ivan's repository Nikolay's repository Natasha's repository Integration repository Trunk repository Central network repositories master master master master master feature_x feature_x test_y BUG!!!

Slide 92

Slide 92 text

Fully distributed Ivan's repository Nikolay's repository Natasha's repository Integration repository Trunk repository Central network repositories master master master master master feature_x feature_x test_y BUG!!! I take it.

Slide 93

Slide 93 text

Fully distributed Ivan's repository Nikolay's repository Natasha's repository Integration repository Trunk repository Central network repositories master master master master master feature_x feature_x test_y bug_y

Slide 94

Slide 94 text

Fully distributed Ivan's repository Nikolay's repository Natasha's repository Integration repository Trunk repository Central network repositories master master master master master feature_x feature_x test_y Ready! bug_y

Slide 95

Slide 95 text

Fully distributed Ivan's repository Nikolay's repository Natasha's repository Integration repository Trunk repository Central network repositories master master master master master feature_x feature_x test_y bug_y

Slide 96

Slide 96 text

Fully distributed Ivan's repository Nikolay's repository Natasha's repository Integration repository Trunk repository Central network repositories master master master master master feature_x feature_x test_y maintenence Ivan, I've done my part

Slide 97

Slide 97 text

Fully distributed Ivan's repository Nikolay's repository Natasha's repository Integration repository Trunk repository Central network repositories master master master master master feature_x feature_x test_y maintenence

Slide 98

Slide 98 text

Fully distributed Ivan's repository Nikolay's repository Natasha's repository Integration repository Trunk repository Central network repositories master master master master master feature_x feature_x maintenence Looks OK!

Slide 99

Slide 99 text

Fully distributed Ivan's repository Nikolay's repository Natasha's repository Integration repository Trunk repository Central network repositories master master master master master feature_x feature_x maintenence test_z

Slide 100

Slide 100 text

Fully distributed Network down Ivan's repository Nikolay's repository Natasha's repository master master master feature_x feature_x test_z BUG!!!

Slide 101

Slide 101 text

Fully distributed Network down Ivan's repository Nikolay's repository Natasha's repository master master master feature_x feature_x test_z BUG!!! I take it.

Slide 102

Slide 102 text

Fully distributed Network down Ivan's repository Nikolay's repository Natasha's repository master master master feature_x feature_x test_z bugfix_z

Slide 103

Slide 103 text

Fully distributed Network down Ivan's repository Nikolay's repository Natasha's repository master master master feature_x feature_x test_z bugfix_z Ready

Slide 104

Slide 104 text

Fully distributed Network down Ivan's repository Nikolay's repository Natasha's repository master master master feature_x feature_x test_z bugfix_z

Slide 105

Slide 105 text

Fully distributed Network down Ivan's repository Nikolay's repository Natasha's repository master master master feature_x feature_x bugfix_z Looks OK! bugfix_z

Slide 106

Slide 106 text

Fully distributed Ivan's repository Nikolay's repository Natasha's repository master master master feature_x feature_x bugfix_z Integration repository Trunk repository Central network repositories master master maintenence

Slide 107

Slide 107 text

Fully distributed Ivan's repository Nikolay's repository Natasha's repository master master master feature_x feature_x Integration repository Trunk repository Central network repositories master master maintenence

Slide 108

Slide 108 text

Fully distributed Ivan's repository Nikolay's repository Natasha's repository master master master feature_x feature_x Integration repository Trunk repository Central network repositories master master maintenence Ready. Need to rebase.

Slide 109

Slide 109 text

Fully distributed Ivan's repository Nikolay's repository Natasha's repository master master master feature_x feature_x Integration repository Trunk repository Central network repositories master master maintenence

Slide 110

Slide 110 text

Fully distributed Ivan's repository Nikolay's repository Natasha's repository master master master feature_x feature_x Integration repository Trunk repository Central network repositories master master maintenence

Slide 111

Slide 111 text

Fully distributed Ivan's repository Nikolay's repository Natasha's repository master master master Integration repository Trunk repository Central network repositories master master maintenence New feature is ready! New feature is ready!

Slide 112

Slide 112 text

Fully distributed Ivan's repository Nikolay's repository Natasha's repository master master master Integration repository Trunk repository Central network repositories master master maintenence regressions

Slide 113

Slide 113 text

Fully distributed Ivan's repository Nikolay's repository Natasha's repository master master master Integration repository Trunk repository Central network repositories master master maintenence Old feature looks done regressions

Slide 114

Slide 114 text

Fully distributed Ivan's repository Nikolay's repository Natasha's repository master master master Integration repository Trunk repository Central network repositories master master maintenence

Slide 115

Slide 115 text

Fully distributed Ivan's repository Nikolay's repository Natasha's repository Integration repository Trunk repository Central network repositories master master master master master

Slide 116

Slide 116 text

GIT workflow

Slide 117

Slide 117 text

GIT workflow ● Create your branch ● Edit files ● Stage your changes ● Commit the changes ● Rebase your branch from master ● Merge to master ● Push to central repository

Slide 118

Slide 118 text

Branches

Slide 119

Slide 119 text

GIT workflow Branching in details A1 master HEAD

Slide 120

Slide 120 text

GIT workflow Branching in details A1 A2 master HEAD

Slide 121

Slide 121 text

GIT workflow Branching in details A1 A2 A3 master HEAD git branch newbranch

Slide 122

Slide 122 text

GIT workflow Branching in details A1 A2 A3 master HEAD newbranch

Slide 123

Slide 123 text

GIT workflow Branching in details A1 A2 A3 master HEAD git checkout newbranch newbranch

Slide 124

Slide 124 text

GIT workflow Branching in details A1 A2 A3 master HEAD newbranch

Slide 125

Slide 125 text

GIT workflow Branching in details A1 A2 A3 master HEAD A4 newbranch

Slide 126

Slide 126 text

GIT workflow Branching in details A1 A2 A3 master HEAD A4 A5 newbranch

Slide 127

Slide 127 text

GIT workflow Branching in details A1 A2 A3 master A4 A5 git checkout master HEAD newbranch

Slide 128

Slide 128 text

GIT workflow Branching in details A1 A2 A3 master HEAD A4 A5 newbranch

Slide 129

Slide 129 text

GIT workflow Branching in details A1 A2 A3 master HEAD A4 A5 newbranch

Slide 130

Slide 130 text

GIT workflow Branching in details A1 A2 A3 master HEAD A4 A5 A6 newbranch

Slide 131

Slide 131 text

GIT workflow Branching in details A1 A2 A3 master HEAD A4 A5 A6 A7 newbranch

Slide 132

Slide 132 text

What's up, folks? This presentation contains 262 slides and looks like that you have reached the midway. Congrats!

Slide 133

Slide 133 text

GIT workflow Branching in details ● Branch pointer always points on the head of a branch; ● Creating branch = creating pointer to commit. 41 bytes on your disk; ● Removing branch is removing pointer. ● Obsolete commits is removed by GIT's GC; ● HEAD meta-tag points to a current active branch; ● One task = one branch.

Slide 134

Slide 134 text

GIT workflow Branching in details ● Branch pointer always points on the head of a branch; ● Creating branch = creating pointer to commit. 41 bytes on your disk; ● Removing branch is removing pointer. ● Obsolete commits is removed by GIT's GC; ● HEAD meta-tag points to a current active branch; ● One task = one branch.

Slide 135

Slide 135 text

GIT workflow ● Create your branch ● Edit files ● Stage your changes ● Commit the changes ● Rebase your branch from master ● Merge to master ● Push to central repository

Slide 136

Slide 136 text

Staging and commiting

Slide 137

Slide 137 text

GIT workflow Staging and commiting Working directory Index Repository

Slide 138

Slide 138 text

GIT workflow Staging and commiting A working copy of your project Working directory Index Repository

Slide 139

Slide 139 text

GIT workflow Staging and commiting Staging area Working directory Index Repository

Slide 140

Slide 140 text

GIT workflow Staging and commiting Object database Working directory Index Repository

Slide 141

Slide 141 text

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

Slide 142

Slide 142 text

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

Slide 143

Slide 143 text

GIT workflow Staging and commiting $ emacs helloworld.c $ cat helloworld.c /* This is a classic 'hello world' app */ int main (int argc, char** argv) { puts("Hello, brave new world!"); return 0; }

Slide 144

Slide 144 text

GIT workflow Staging and commiting $ emacs helloworld.c $ cat helloworld.c /* This is a classic 'hello world' app */ int main (int argc, char** argv) { puts("Hello, brave new world!"); return 0; }

Slide 145

Slide 145 text

GIT workflow Staging and commiting $ git status # On branch master # # Initial commit # # Untracked files: # (use "git add ..." to include in what will be committed) # # helloworld.c nothing added to commit but untracked files present (use "git add" to track)

Slide 146

Slide 146 text

GIT workflow Staging and commiting $ git status # On branch master # # Initial commit # # Untracked files: # (use "git add ..." to include in what will be committed) # # helloworld.c nothing added to commit but untracked files present (use "git add" to track)

Slide 147

Slide 147 text

GIT workflow Staging and commiting $ git add helloworld.c $ git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached ..." to unstage) # # new file: helloworld.c #

Slide 148

Slide 148 text

GIT workflow Staging and commiting $ git add helloworld.c $ git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached ..." to unstage) # # new file: helloworld.c #

Slide 149

Slide 149 text

GIT workflow Staging and commiting $ git commit -m "Useful comment" [master (root-commit) 23409d6] Useful comment 1 files changed, 7 insertions(+), 0 deletions(-) create mode 100644 helloworld.c

Slide 150

Slide 150 text

GIT workflow Staging and commiting $ emacs helloworld.c $ cat helloworld.c /* This is a classic 'hello world' app */ #include int main (int argc, char** argv) { puts("Hello, brave new world!"); return 0; }

Slide 151

Slide 151 text

GIT workflow Staging and commiting $ 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: helloworld.c # no changes added to commit (use "git add" and/or "git commit -a")

Slide 152

Slide 152 text

GIT workflow Staging and commiting $ 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: helloworld.c # no changes added to commit (use "git add" and/or "git commit -a")

Slide 153

Slide 153 text

GIT workflow Staging and commiting $ 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: helloworld.c # no changes added to commit (use "git add" and/or "git commit -a")

Slide 154

Slide 154 text

GIT workflow Staging and commiting $ git diff --- a/helloworld.c +++ b/helloworld.c @@ -1,5 +1,7 @@ /* This is a classic 'hello world' app */ +#include + int main (int argc, char** argv) { puts("Hello, brave new world!");

Slide 155

Slide 155 text

GIT workflow Staging and commiting $ git diff --- a/helloworld.c +++ b/helloworld.c @@ -1,5 +1,7 @@ /* This is a classic 'hello world' app */ +#include + int main (int argc, char** argv) { puts("Hello, brave new world!");

Slide 156

Slide 156 text

GIT workflow Staging and commiting $ git add helloworld.c $ git status # On branch master # Changes to be committed: # (use "git reset HEAD ..." to unstage) # # modified: helloworld.c #

Slide 157

Slide 157 text

GIT workflow Staging and commiting $ emacs helloworld.c $ cat helloworld.c /* This is a classic 'hello world' app */ #include int main (int argc, char** argv) { printf("Hello, brave new world!\n"); return 0; }

Slide 158

Slide 158 text

GIT workflow Staging and commiting $ git status # On branch master # Changes to be committed: # (use "git reset HEAD ..." to unstage) # # modified: helloworld.c # # Changes not staged for commit: # (use "git add ..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working directory) # # modified: helloworld.c #

Slide 159

Slide 159 text

GIT workflow Staging and commiting $ git status # On branch master # Changes to be committed: # (use "git reset HEAD ..." to unstage) # # modified: helloworld.c # # Changes not staged for commit: # (use "git add ..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working directory) # # modified: helloworld.c #

Slide 160

Slide 160 text

GIT workflow Staging and commiting $ git diff --- a/helloworld.c +++ b/helloworld.c @@ -4,6 +4,6 @@ int main (int argc, char** argv) { - puts("Hello, brave new world!"); + printf("Hello, brave new world!\n"); return 0; }

Slide 161

Slide 161 text

GIT workflow Staging and commiting $ git diff --- a/helloworld.c +++ b/helloworld.c @@ -4,6 +4,6 @@ int main (int argc, char** argv) { - puts("Hello, brave new world!"); + printf("Hello, brave new world!\n"); return 0; }

Slide 162

Slide 162 text

WTF?

Slide 163

Slide 163 text

GIT workflow Staging and commiting Working directory Index Repository

Slide 164

Slide 164 text

GIT workflow Staging and commiting Working directory Index Repository git add

Slide 165

Slide 165 text

GIT workflow Staging and commiting Working directory Index Repository git add git commit

Slide 166

Slide 166 text

GIT workflow Staging and commiting $ git status # On branch master # Changes to be committed: # (use "git reset HEAD ..." to unstage) # # modified: helloworld.c # # Changes not staged for commit: # (use "git add ..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working directory) # # modified: helloworld.c #

Slide 167

Slide 167 text

GIT workflow Staging and commiting $ git status # On branch master # Changes that are staged: # (use "git reset HEAD ..." to unstage) # # modified: helloworld.c # # Changes that are not staged: # (use "git add ..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working directory) # # modified: helloworld.c #

Slide 168

Slide 168 text

GIT workflow Staging and commiting Staged $ git status # On branch master # Changes to be committed: # (use "git reset HEAD ..." to unstage) # # modified: helloworld.c # # Changes not staged for commit: # (use "git add ..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working directory) # # modified: helloworld.c #

Slide 169

Slide 169 text

GIT workflow Staging and commiting Not staged $ git status # On branch master # Changes to be committed: # (use "git reset HEAD ..." to unstage) # # modified: helloworld.c # # Changes not staged for commit: # (use "git add ..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working directory) # # modified: helloworld.c #

Slide 170

Slide 170 text

GIT workflow Staging and commiting Please use git diff --cached to get expected output here.

Slide 171

Slide 171 text

GIT workflow Staging and commiting You have to stage a file after you edit it

Slide 172

Slide 172 text

GIT workflow Staging and commiting You have to stage a file after you edit it

Slide 173

Slide 173 text

GIT workflow Staging and commiting You have to stage a file after you edit it

Slide 174

Slide 174 text

GIT workflow Staging and commiting $ git commit -a Hello world of a new generation. # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch master # Changes to be committed: # (use "git reset HEAD ..." to unstage) # # modified: helloworld.c #

Slide 175

Slide 175 text

GIT workflow Staging and commiting [master 4bbbef9] Hello world of a new generation. 1 files changed, 3 insertions(+), 1 deletions(-)

Slide 176

Slide 176 text

GIT workflow Staging and commiting [master 4bbbef9] Hello world of a new generation. 1 files changed, 3 insertions(+), 1 deletions(-)

Slide 177

Slide 177 text

GIT workflow Staging and commiting 4bbbef9

Slide 178

Slide 178 text

GIT workflow Staging and commiting 4bbbef94bbbef9b703c8197ec34cb90382c7b8fd5046a9a

Slide 179

Slide 179 text

GIT workflow Staging and commiting $ tree -a . ├── .git │ ├── branches │ ├── COMMIT_EDITMSG │ ├── config │ ├── description │ ├── HEAD │ ├── hooks │ │ ├── applypatch-msg.sample │ │ ├── ... │ ├── index │ ├── info │ │ └── exclude │ ├── logs │ │ ├── HEAD │ │ └── refs │ │ └── heads │ │ └── master │ ├── objects │ │ ├── 23 │ │ │ └── 409d6895e7cb65306d4ed7d0c558ced6c82753 │ │ ├── ... │ │ ├── info │ │ └── pack │ └── refs │ ├── heads │ │ └── master │ └── tags └── helloworld.c

Slide 180

Slide 180 text

GIT workflow Staging and commiting 4bbbef94bbbef9b703c8197ec34cb90382c7b8fd5046a9a commit Size Tree Parent Author Commiter c4ec5 d8a16 Ivan Petr Hello world of a new generation.

Slide 181

Slide 181 text

GIT workflow Staging and commiting 4bbbef94bbbef9b703c8197ec34cb90382c7b8fd5046a9a commit Size Tree Parent Author Commiter c4ec5 d8a16 Ivan Petr Hello world of a new generation. ./ c4ec5 helloworld.c c4ec5

Slide 182

Slide 182 text

GIT workflow Staging and commiting 4bbbef94bbbef9b703c8197ec34cb90382c7b8fd5046a9a commit Size Tree Parent Author Commiter cfbb1 cae87 Ivan Petr Initial commit. commit Size Tree Parent Author Commiter c4ec5 d8a16 Ivan Petr Hello world of a new generation.

Slide 183

Slide 183 text

GIT workflow Staging and commiting Repository c1e fa8 135 47b aba a5b ccc cfe c0d 0aa 17f ffe 9b4 400 813

Slide 184

Slide 184 text

GIT workflow Staging and commiting Repository git checkout 47b c1e fa8 135 47b aba a5b ccc cfe c0d 0aa 17f ffe 9b4 400 813

Slide 185

Slide 185 text

GIT workflow Staging and commiting Repository git checkout 47b c1e fa8 135 47b aba a5b ccc cfe c0d 0aa 17f ffe 9b4 400 813

Slide 186

Slide 186 text

GIT workflow Staging and commiting Repository git checkout 47b c1e fa8 135 47b aba a5b ccc cfe c0d 0aa 17f ffe 9b4 400 813

Slide 187

Slide 187 text

GIT workflow Staging and commiting Repository Index ./ helloworld.c farewell.c ccc cfe aba c1e fa8 135 47b aba a5b ccc cfe c0d 0aa 17f ffe 9b4 400 813

Slide 188

Slide 188 text

GIT workflow Staging and commiting Repository Index Working directory ./ helloworld.c farewell.c ccc cfe aba ./ helloworld.c farewell.c c1e fa8 135 47b aba a5b ccc cfe c0d 0aa 17f ffe 9b4 400 813

Slide 189

Slide 189 text

GIT workflow Staging and commiting Repository Index Working directory ./ helloworld.c farewell.c ccc cfe aba ./ helloworld.c farewell.c c1e fa8 135 47b aba a5b ccc cfe c0d 0aa 17f ffe 9b4 400 813

Slide 190

Slide 190 text

GIT workflow Staging and commiting Repository Index Working directory ./ helloworld.c farewell.c ccc cfe aba ./ helloworld.c farewell.c c1e fa8 135 47b aba a5b ccc cfe c0d 0aa 17f ffe 9b4 400 813

Slide 191

Slide 191 text

GIT workflow Staging and commiting Repository Index Working directory ./ helloworld.c farewell.c ccc cfe aba ./ helloworld.c farewell.c git add c1e fa8 135 47b aba a5b ccc cfe c0d 0aa 17f ffe 9b4 400 813

Slide 192

Slide 192 text

GIT workflow Staging and commiting Repository Index Working directory ./ helloworld.c farewell.c ccc cfe aba ./ helloworld.c farewell.c c1e fa8 135 47b aba a5b ccc cfe c0d 0aa 17f ffe 9b4 400 813

Slide 193

Slide 193 text

GIT workflow Staging and commiting Repository Index Working directory ./ helloworld.c farewell.c ccc cfe aba ./ helloworld.c farewell.c afa 13a c1e fa8 135 47b aba a5b ccc cfe c0d 0aa 17f ffe 9b4 400 813

Slide 194

Slide 194 text

GIT workflow Staging and commiting Repository Index Working directory ./ helloworld.c farewell.c ccc cfe aba ./ helloworld.c farewell.c afa 13a git commit c1e fa8 135 47b aba a5b ccc cfe c0d 0aa 17f ffe 9b4 400 813

Slide 195

Slide 195 text

GIT workflow Staging and commiting Repository Index Working directory ./ helloworld.c farewell.c ccc cfe aba ./ helloworld.c farewell.c afa 13a c1e fa8 135 47b aba a5b ccc cfe c0d 0aa 17f ffe 9b4 400 13a 813 afa ae7

Slide 196

Slide 196 text

GIT workflow Staging and commiting Repository Index Working directory c1e fa8 135 47b aba a5b ccc cfe c0d 0aa 17f ffe 9b4 400 13a 813 afa ae7 ./ helloworld.c farewell.c 13a afa aba ./ helloworld.c farewell.c

Slide 197

Slide 197 text

GIT workflow Staging and commiting Repository Index Working directory c1e fa8 135 47b aba a5b ccc cfe c0d 0aa 17f ffe 9b4 400 13a 813 afa ae7 ./ helloworld.c farewell.c 13a afa aba ./ helloworld.c farewell.c

Slide 198

Slide 198 text

GIT workflow ● Create your branch ● Edit files ● Stage your changes ● Commit the changes ● Rebase your branch from master ● Merge to master ● Push to central repository

Slide 199

Slide 199 text

Rebasing

Slide 200

Slide 200 text

GIT workflow Rebasing A1 A2 A3 master HEAD branch A4 A5 A6 A7

Slide 201

Slide 201 text

GIT workflow Rebasing A1 A2 A3 master HEAD branch A4 A5 A6 A7 git rebase master

Slide 202

Slide 202 text

GIT workflow Rebasing A1 A2 A3 master HEAD branch A6 A7 A8 A9

Slide 203

Slide 203 text

Huh? Where is my A4 and A5? What is happening?

Slide 204

Slide 204 text

GIT workflow Rebasing A1 A2 A3 master HEAD branch A4 A5 A6 A7 git rebase master

Slide 205

Slide 205 text

GIT workflow Rebasing A1 A2 A3 master HEAD branch A4 A5 A6 A7 A8 A8 = A7 with A4 patch

Slide 206

Slide 206 text

GIT workflow Rebasing A1 A2 A3 master HEAD branch A4 A5 A6 A7 A8 A9 = A8 with A5 patch A9

Slide 207

Slide 207 text

GIT workflow Rebasing A1 A2 A3 master HEAD branch A4 A5 A6 A7 A8 A9

Slide 208

Slide 208 text

GIT workflow Rebasing A1 A2 A3 master HEAD branch A4 A5 A6 A7 A8 A9

Slide 209

Slide 209 text

GIT workflow Rebasing A1 A2 A3 master HEAD branch A6 A7 A8 A9

Slide 210

Slide 210 text

GIT workflow Rebasing A1 A2 A3 master HEAD branch A6 A7 A8 A9

Slide 211

Slide 211 text

GIT workflow Rebasing Never rebase when you are on a shared branch

Slide 212

Slide 212 text

GIT workflow Rebasing Never rebase when you are on a shared branch

Slide 213

Slide 213 text

GIT workflow Rebasing Never rebase a shared branch

Slide 214

Slide 214 text

GIT workflow Rebasing Never rebase a shared branch* * Or learn git reflog

Slide 215

Slide 215 text

GIT workflow Rebasing A1 A2 A3 master HEAD branch A4 A5 A6 A7

Slide 216

Slide 216 text

GIT workflow Rebasing A1 A2 A3 master HEAD branch A4 A5 A6 A7 git checkout master

Slide 217

Slide 217 text

GIT workflow Rebasing A1 A2 A3 master HEAD branch A4 A5 A6 A7

Slide 218

Slide 218 text

GIT workflow Rebasing A1 A2 A3 master HEAD branch A4 A5 A6 A7 git rebase branch

Slide 219

Slide 219 text

GIT workflow Rebasing A1 A2 A3 master HEAD branch A4 A5 A6 A7

Slide 220

Slide 220 text

GIT workflow Rebasing A1 A2 A3 master HEAD branch A4 A5 A6 A7 A8 A8 = A5 with A6 patch

Slide 221

Slide 221 text

GIT workflow Rebasing A1 A2 A3 master HEAD branch A4 A5 A6 A7 A8 A9 = A8 with A7 patch A9

Slide 222

Slide 222 text

GIT workflow Rebasing A1 A2 A3 master HEAD branch A4 A5 A6 A7 A8 Now A6 and A7 commits will be deleted. Forever. A9

Slide 223

Slide 223 text

GIT workflow Rebasing A1 A2 A3 master HEAD branch A4 A5 A8 You have broken common branch. If you push it somewhere, it will break other's ones. A9

Slide 224

Slide 224 text

GIT workflow Rebasing Never rebase a shared branch, you idiot!

Slide 225

Slide 225 text

GIT workflow ● Create your branch ● Edit files ● Stage your changes ● Commit the changes ● Rebase your branch from master ● Merge to master ● Push to central repository

Slide 226

Slide 226 text

Merges

Slide 227

Slide 227 text

GIT workflow Merges A1 A2 A3 master HEAD branch A4 A5 A6 A7

Slide 228

Slide 228 text

GIT workflow Merges A1 A2 A3 master HEAD branch A4 A5 A6 A7 git merge branch

Slide 229

Slide 229 text

GIT workflow Merges A1 A2 A3 master HEAD branch A4 A5 A6 A7 A8

Slide 230

Slide 230 text

Have you really thought that GIT have complicated merges?

Slide 231

Slide 231 text

GIT workflow ● Create your branch ● Edit files ● Stage your changes ● Commit the changes ● Rebase your branch from master ● Merge to master ● Push to central repository

Slide 232

Slide 232 text

Push and pull

Slide 233

Slide 233 text

GIT workflow Push and pull Remote repository Local repository A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A1 A2 A3 A4 A11 A13 master master hotfix feature HEAD

Slide 234

Slide 234 text

GIT workflow Push and pull git fetch

Slide 235

Slide 235 text

GIT workflow Push and pull Remote repository Local repository A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A1 A2 A3 A4 A11 A13 master master hotfix feature HEAD git fetch remote

Slide 236

Slide 236 text

GIT workflow Push and pull Remote repository Local repository A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A1 A2 A3 A4 A11 A13 master master hotfix feature HEAD A5 A6 A7 A8 A9 A10 A10

Slide 237

Slide 237 text

GIT workflow Push and pull Remote repository Local repository A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A1 A2 A3 A4 A11 A13 master master hotfix feature HEAD A5 A6 A7 A8 A9 A10 A10

Slide 238

Slide 238 text

GIT workflow Push and pull Remote repository Local repository A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A1 A2 A3 A4 A11 A13 master master hotfix feature HEAD A5 A6 A7 A8 A9 A10 A10 remote/master remote/hotfix

Slide 239

Slide 239 text

GIT workflow Push and pull git pull

Slide 240

Slide 240 text

GIT workflow Push and pull pull = fetch + merge

Slide 241

Slide 241 text

GIT workflow Push and pull git push

Slide 242

Slide 242 text

GIT workflow Push and pull Remote repository Local repository A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A1 A2 A3 A4 A11 A13 master master hotfix feature HEAD

Slide 243

Slide 243 text

GIT workflow Push and pull Remote repository Local repository A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A1 A2 A3 A4 A11 A13 master master hotfix feature HEAD git push remote feature

Slide 244

Slide 244 text

GIT workflow Push and pull Remote repository Local repository A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A1 A2 A3 A4 A11 A13 master master hotfix feature HEAD A11 A13

Slide 245

Slide 245 text

GIT workflow Push and pull Remote repository Local repository A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A1 A2 A3 A4 A11 A13 master master hotfix feature HEAD A11 A13

Slide 246

Slide 246 text

GIT workflow Push and pull Remote repository Local repository A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A1 A2 A3 A4 A11 A13 master master hotfix feature HEAD A11 A13 feature

Slide 247

Slide 247 text

GIT workflow Push and pull Remote repository Local repository A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A1 A2 A3 A4 A11 A13 master master hotfix feature HEAD A11 A13 feature git push remote master

Slide 248

Slide 248 text

GIT workflow Push and pull Remote repository Local repository A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A1 A2 A3 A4 A11 A13 master master hotfix feature HEAD A11 A13 feature To ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to '' To prevent you from losing history, Non-fast-forward updates were rejected Merge the remote changes (e.g. 'git pull') before pushing again. See the 'Note about fast-forwards' section of 'git push —help' for details.

Slide 249

Slide 249 text

GIT workflow Push and pull Remote repository Local repository A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A1 A2 A3 A4 A11 A13 master master hotfix feature HEAD A11 A13 feature To ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to '' To prevent you from losing history, Non-fast-forward updates were rejected Merge the remote changes (e.g. 'git pull') before pushing again. See the 'Note about fast-forwards' section of 'git push —help' for details.

Slide 250

Slide 250 text

GIT workflow Push and pull git push is about fast-forward merges

Slide 251

Slide 251 text

GIT workflow Push and pull Always pull before push!

Slide 252

Slide 252 text

GIT workflow Push and pull Always pull before push!

Slide 253

Slide 253 text

GIT workflow ● Create your branch ● Edit files ● Stage your changes ● Commit the changes ● Rebase your branch from master ● Merge to master ● Push to central repository

Slide 254

Slide 254 text

There are only 5 slides left. Cheer up!

Slide 255

Slide 255 text

Must-have commands

Slide 256

Slide 256 text

Must-have commands git diff git status git clone git merge git add git log git commit git push git branch git pull git blame git fetch 12 commands

Slide 257

Slide 257 text

Some tools

Slide 258

Slide 258 text

Some tools gitk

Slide 259

Slide 259 text

Some tools tig

Slide 260

Slide 260 text

Credits

Slide 261

Slide 261 text

Credits ● Git Community Book ● ProGit ● Help on GitHub ● Linus Torvalds on GIT ● StackOverflow GIT tag ● GIT Magic ● GIT Immersion ● GITCasts ● GIT Wizardry ● GIT Manual ● GIT official site ● GIT Reference

Slide 262

Slide 262 text

that's it!