1
00:00:00,000 --> 00:00:00,930
In this lesson,

2
00:00:00,930 --> 00:00:03,330
I'm going to demonstrate how you can use source control

3
00:00:03,330 --> 00:00:05,580
like Git to keep track of your files

4
00:00:05,580 --> 00:00:07,230
when you're working as a team.

5
00:00:07,230 --> 00:00:09,810
Now, Git is pretty much the defacto standard these days

6
00:00:09,810 --> 00:00:11,340
for code repositories.

7
00:00:11,340 --> 00:00:12,660
And so, as we go through this,

8
00:00:12,660 --> 00:00:14,490
I'm going to show you a couple of simple things

9
00:00:14,490 --> 00:00:15,570
you can do with Git,

10
00:00:15,570 --> 00:00:17,160
but, really, the point is not for you

11
00:00:17,160 --> 00:00:19,170
to learn how to do this and be hands-on,

12
00:00:19,170 --> 00:00:22,200
I just want to demonstrate the capability of a tool like Git,

13
00:00:22,200 --> 00:00:24,330
but you are not going to be tested on specific things

14
00:00:24,330 --> 00:00:26,370
of how to use Git on the exam.

15
00:00:26,370 --> 00:00:29,370
Instead, you need to understand why you would use Git.

16
00:00:29,370 --> 00:00:30,210
And for the most part,

17
00:00:30,210 --> 00:00:32,490
you're going to use Git to be able to do version control

18
00:00:32,490 --> 00:00:35,610
and source control of your code for your templates,

19
00:00:35,610 --> 00:00:37,980
run books, infrastructure as code,

20
00:00:37,980 --> 00:00:39,810
and other scripts and files.

21
00:00:39,810 --> 00:00:41,490
All right, let's get started.

22
00:00:41,490 --> 00:00:42,600
Now the first thing we're going to do

23
00:00:42,600 --> 00:00:43,680
when we start working with Git

24
00:00:43,680 --> 00:00:45,210
is we want to make sure we're setting it up

25
00:00:45,210 --> 00:00:46,530
with our username and email

26
00:00:46,530 --> 00:00:48,450
so people know who's making changes

27
00:00:48,450 --> 00:00:50,670
when we're interacting with a Git repository.

28
00:00:50,670 --> 00:00:52,020
To do this, we're going to change

29
00:00:52,020 --> 00:00:54,357
something known as a global variable inside of Git,

30
00:00:54,357 --> 00:00:59,357
and you just by typing git config --global user.name,

31
00:01:01,380 --> 00:01:03,030
which is the variable that I want to change,

32
00:01:03,030 --> 00:01:04,560
in this case, my username,

33
00:01:04,560 --> 00:01:06,240
and then I want to put in my username.

34
00:01:06,240 --> 00:01:08,370
So I'm going to go ahead and put in 'Jason Dion'.

35
00:01:08,370 --> 00:01:13,370
Next, we want to type in git config --global user.mail,

36
00:01:14,250 --> 00:01:15,900
and we're going to put in our email address,

37
00:01:15,900 --> 00:01:18,963
which in my case is support@diontraining.com.

38
00:01:20,820 --> 00:01:21,780
Once you hit Enter,

39
00:01:21,780 --> 00:01:23,400
you'll see we're back at the command prompt.

40
00:01:23,400 --> 00:01:24,540
Now if you got an error,

41
00:01:24,540 --> 00:01:26,550
that means something went wrong and we need to fix it,

42
00:01:26,550 --> 00:01:28,050
but with Git, most of the time,

43
00:01:28,050 --> 00:01:29,190
you're not going to get a response

44
00:01:29,190 --> 00:01:31,380
except to be returned back to the command prompt,

45
00:01:31,380 --> 00:01:33,810
which means you can assume it was successful.

46
00:01:33,810 --> 00:01:35,640
The next thing I want to do is make a directory

47
00:01:35,640 --> 00:01:36,930
for us to play inside of.

48
00:01:36,930 --> 00:01:41,040
So I'm just going to create a directory called TEST-PROJECT.

49
00:01:41,040 --> 00:01:43,590
Now that I've done that, if I type in ls,

50
00:01:43,590 --> 00:01:45,330
you will see there is one directory there

51
00:01:45,330 --> 00:01:47,280
called TEST-PROJECT.

52
00:01:47,280 --> 00:01:48,330
Now for me to be able to use this,

53
00:01:48,330 --> 00:01:51,120
I need to initialize it as a Git repository.

54
00:01:51,120 --> 00:01:54,450
So I'm going to type in git init, for init,

55
00:01:54,450 --> 00:01:56,610
and in space and the name of the directory

56
00:01:56,610 --> 00:01:58,980
that we just created and hit Enter.

57
00:01:58,980 --> 00:02:00,090
Once we've done that,

58
00:02:00,090 --> 00:02:02,460
we now can see that the Git repository

59
00:02:02,460 --> 00:02:03,990
has been initialized as empty

60
00:02:03,990 --> 00:02:05,730
inside of jason's Download folder

61
00:02:05,730 --> 00:02:07,200
underneath the PROJECT directory,

62
00:02:07,200 --> 00:02:09,300
underneath the TEST-PROJECT directory,

63
00:02:09,300 --> 00:02:13,380
and then under the .git directory, or .git directory.

64
00:02:13,380 --> 00:02:15,570
And this is a directory that's going to hold all of the files

65
00:02:15,570 --> 00:02:17,100
for that Git repository,

66
00:02:17,100 --> 00:02:18,840
and then any of the files we want to control,

67
00:02:18,840 --> 00:02:20,790
we're going to place inside of TEST-PROJECT

68
00:02:20,790 --> 00:02:23,040
and then add them into the Git repository

69
00:02:23,040 --> 00:02:24,870
by creating a symbolic link.

70
00:02:24,870 --> 00:02:25,890
Now to look inside this,

71
00:02:25,890 --> 00:02:27,360
we're going to do a cd

72
00:02:27,360 --> 00:02:30,420
and then we're going to do TEST-PROJECT and hit Enter.

73
00:02:30,420 --> 00:02:32,790
And then we're going to type in ls -la,

74
00:02:32,790 --> 00:02:34,290
and this will list out all the things

75
00:02:34,290 --> 00:02:36,330
inside the TEST-PROJECT directory.

76
00:02:36,330 --> 00:02:38,580
Notice we have three things, ., .., and .git.

77
00:02:40,740 --> 00:02:42,780
Now if you think back to your earlier studies,

78
00:02:42,780 --> 00:02:44,550
you should know that in a Linux system,

79
00:02:44,550 --> 00:02:46,860
a . means the present working directory

80
00:02:46,860 --> 00:02:48,810
or the directory we're currently in,

81
00:02:48,810 --> 00:02:53,810
which is users/jason/Downloads/PROJECT/TEST-PROJECT.

82
00:02:54,360 --> 00:02:56,640
The .. is one directory higher.

83
00:02:56,640 --> 00:02:58,980
In this case, that would be the PROJECT directory

84
00:02:58,980 --> 00:03:00,270
'cause that is one directory up

85
00:03:00,270 --> 00:03:03,060
from our current directory of the TEST-PROJECT.

86
00:03:03,060 --> 00:03:04,980
That's going to happen on every window system,

87
00:03:04,980 --> 00:03:06,840
every Unix system, every Linux system,

88
00:03:06,840 --> 00:03:09,840
and every Mac system, like the one I'm using here.

89
00:03:09,840 --> 00:03:11,940
The third one we have is the .git,

90
00:03:11,940 --> 00:03:14,910
and the .git is going to hold all of those files for us

91
00:03:14,910 --> 00:03:15,960
inside of it.

92
00:03:15,960 --> 00:03:18,270
We're going to just go in there by doing a cd command,

93
00:03:18,270 --> 00:03:20,430
and then we're going to do ls -la again.

94
00:03:20,430 --> 00:03:22,650
And here you can see what we're going to have.

95
00:03:22,650 --> 00:03:25,950
In here, we have a couple of files like the head file,

96
00:03:25,950 --> 00:03:28,020
the config file, and the description file,

97
00:03:28,020 --> 00:03:29,610
and then we have several directories,

98
00:03:29,610 --> 00:03:33,510
which is the branches, hooks, info, objects and ref.

99
00:03:33,510 --> 00:03:35,940
And all these are things that are created and they are empty

100
00:03:35,940 --> 00:03:38,250
because we don't have anything in this Git repository yet,

101
00:03:38,250 --> 00:03:39,570
except the structure,

102
00:03:39,570 --> 00:03:42,450
but every Git repository will have this structure.

103
00:03:42,450 --> 00:03:43,950
All right, let me go back up one directory,

104
00:03:43,950 --> 00:03:45,981
back into the TEST-PROJECT directory

105
00:03:45,981 --> 00:03:47,820
and then I'm going to go ahead and clear my screen.

106
00:03:47,820 --> 00:03:49,343
Now for us to be able to use Git,

107
00:03:49,343 --> 00:03:52,320
we have to have some files to add to our Git repository.

108
00:03:52,320 --> 00:03:55,710
So let's go ahead and create a text file by typing in vim,

109
00:03:55,710 --> 00:03:58,470
which is a text editor inside of Unix, Linux,

110
00:03:58,470 --> 00:03:59,850
and Mac-type systems,

111
00:03:59,850 --> 00:04:03,000
and I'm just going to give it a file name of test.txt.

112
00:04:03,000 --> 00:04:05,520
Once I hit Enter, I'm now in the Vim editor

113
00:04:05,520 --> 00:04:07,650
and I'll press I to enter insert mode,

114
00:04:07,650 --> 00:04:09,360
and now I can write whatever I want.

115
00:04:09,360 --> 00:04:12,450
For example, I could say, "This is a script

116
00:04:12,450 --> 00:04:14,610
that Jason has written."

117
00:04:14,610 --> 00:04:15,900
Now that we've done typing what we want,

118
00:04:15,900 --> 00:04:19,589
we'll press the Escape key, :, and then wq,

119
00:04:19,589 --> 00:04:22,410
which stands for write and quit, and hit Enter.

120
00:04:22,410 --> 00:04:24,600
Once we've done that, we're back in our directory.

121
00:04:24,600 --> 00:04:26,610
And now we want to see if it actually did anything

122
00:04:26,610 --> 00:04:27,600
inside of that file.

123
00:04:27,600 --> 00:04:30,450
So I'm going to type in the word cat and then test.txt,

124
00:04:30,450 --> 00:04:32,190
which will print the contents to the screen,

125
00:04:32,190 --> 00:04:34,740
which should say, "This is a script written by Jason."

126
00:04:34,740 --> 00:04:37,230
And now you can see that we do have the test.txt file

127
00:04:37,230 --> 00:04:38,400
inside of this directory,

128
00:04:38,400 --> 00:04:41,010
which is called the TEST-PROJECT directory.

129
00:04:41,010 --> 00:04:43,980
Now from here, what we want to do is check our Git repository

130
00:04:43,980 --> 00:04:46,560
and see does it realize any changes have occurred.

131
00:04:46,560 --> 00:04:48,390
So we'll type in git status,

132
00:04:48,390 --> 00:04:50,190
and this will always tell us the latest status

133
00:04:50,190 --> 00:04:51,720
of our Git repository.

134
00:04:51,720 --> 00:04:54,420
From here, you can see that I'm on the branch master,

135
00:04:54,420 --> 00:04:55,920
I have no commits yet,

136
00:04:55,920 --> 00:04:58,380
and at this point, it notices there is one file

137
00:04:58,380 --> 00:05:02,070
called test.txt, but it's under the untracked files

138
00:05:02,070 --> 00:05:03,660
because we never told Git

139
00:05:03,660 --> 00:05:05,370
we want it to think about this file

140
00:05:05,370 --> 00:05:07,350
and to track any changes that happens.

141
00:05:07,350 --> 00:05:09,810
So all it's saying is, "Hey, there's a new file here,

142
00:05:09,810 --> 00:05:11,550
I'm not really tracking it, but there is a new file,

143
00:05:11,550 --> 00:05:12,780
you might want to look at it."

144
00:05:12,780 --> 00:05:14,820
And so in this case, it says nothing was added to the commit

145
00:05:14,820 --> 00:05:16,890
but there was an untracked file present.

146
00:05:16,890 --> 00:05:19,350
Now I know what that file is 'cause I just created it,

147
00:05:19,350 --> 00:05:21,360
and I want to add that to my Git repository.

148
00:05:21,360 --> 00:05:22,350
So if we make changes,

149
00:05:22,350 --> 00:05:24,690
it'll notify us of those changes in the future.

150
00:05:24,690 --> 00:05:26,910
To do that, we're just going to type in the word git,

151
00:05:26,910 --> 00:05:28,950
and then add, and then the name of the file,

152
00:05:28,950 --> 00:05:31,290
which is test.txt.

153
00:05:31,290 --> 00:05:35,160
From there, we're now going to do a git status once more,

154
00:05:35,160 --> 00:05:36,720
and we should get a similar error,

155
00:05:36,720 --> 00:05:38,040
but you're going to see that it's added

156
00:05:38,040 --> 00:05:39,930
but the changes haven't been done.

157
00:05:39,930 --> 00:05:42,630
So here you can see that we have a new file in green

158
00:05:42,630 --> 00:05:44,490
and it's ready to be committed.

159
00:05:44,490 --> 00:05:46,800
To commit those changes to the Git repository,

160
00:05:46,800 --> 00:05:49,080
we'll type in git and then the word commit,

161
00:05:49,080 --> 00:05:51,750
and then I'm going to use -m, which stands for message,

162
00:05:51,750 --> 00:05:54,510
and I can put whatever comment or message I want here.

163
00:05:54,510 --> 00:05:56,910
So I'm just going to say this is the initial commit

164
00:05:57,960 --> 00:06:02,960
with one file called text.txt, and I'll hit Enter.

165
00:06:03,900 --> 00:06:04,733
And there we go.

166
00:06:04,733 --> 00:06:07,560
We have now committed the one file called text.txt.

167
00:06:07,560 --> 00:06:09,990
One file was changed, one file was inserted,

168
00:06:09,990 --> 00:06:13,080
and it was in create mode for test.txt.

169
00:06:13,080 --> 00:06:14,310
Now at this point,

170
00:06:14,310 --> 00:06:16,470
if we go ahead and do a git status,

171
00:06:16,470 --> 00:06:19,230
we should see that everything looks clean and clear.

172
00:06:19,230 --> 00:06:21,000
And you can see we are on the branch master,

173
00:06:21,000 --> 00:06:23,610
there's nothing to commit, and is a working tree clean,

174
00:06:23,610 --> 00:06:25,470
which means all the files are in sync

175
00:06:25,470 --> 00:06:28,770
and nobody's modified a file since we did the last commit,

176
00:06:28,770 --> 00:06:30,360
which is true because we just did the commit

177
00:06:30,360 --> 00:06:31,770
and haven't done anything else.

178
00:06:31,770 --> 00:06:34,140
So we're going to go back into Vim to add a new line to this

179
00:06:34,140 --> 00:06:36,480
by going vim test.txt,

180
00:06:36,480 --> 00:06:38,160
and then we're going to hit the I for insert.

181
00:06:38,160 --> 00:06:40,470
We'll arrow over to the end of the line.

182
00:06:40,470 --> 00:06:43,860
And then from here, I'm just going to put . and hit Enter,

183
00:06:43,860 --> 00:06:48,860
and I'll say, "Let's pretend I added a new line

184
00:06:49,500 --> 00:06:51,027
to a Python script!"

185
00:06:52,500 --> 00:06:54,941
Okay, and then we're going to hit Escape,

186
00:06:54,941 --> 00:06:59,130
:wq, for write and quit, and there we go.

187
00:06:59,130 --> 00:07:01,800
Now from here, if I do the cat test.txt,

188
00:07:01,800 --> 00:07:03,270
we should see the change we made.

189
00:07:03,270 --> 00:07:06,330
You can see there's now two lines to script instead of one.

190
00:07:06,330 --> 00:07:09,360
The next thing we want to do is we want to do a git status.

191
00:07:09,360 --> 00:07:11,640
Now will there be any changes to this file

192
00:07:11,640 --> 00:07:12,930
that Git's going to recognize?

193
00:07:12,930 --> 00:07:14,970
There should be 'cause we added a whole new line.

194
00:07:14,970 --> 00:07:15,990
And so you'll see what happens

195
00:07:15,990 --> 00:07:17,730
is that we are on the branch master,

196
00:07:17,730 --> 00:07:19,800
changes not staged for commit.

197
00:07:19,800 --> 00:07:23,040
And it shows in red, test.txt was modified.

198
00:07:23,040 --> 00:07:25,230
Now it's just telling us that the file was changed.

199
00:07:25,230 --> 00:07:26,400
If we went in further,

200
00:07:26,400 --> 00:07:28,950
we could actually log every single change and know it.

201
00:07:28,950 --> 00:07:29,783
But right now,

202
00:07:29,783 --> 00:07:31,320
we're just worried about the fact that this changed,

203
00:07:31,320 --> 00:07:32,730
and that's good enough for now.

204
00:07:32,730 --> 00:07:35,220
And so we know there are no changes added to the commit.

205
00:07:35,220 --> 00:07:37,950
If we want to add this file back to the commit

206
00:07:37,950 --> 00:07:39,930
so we can put it into the repo,

207
00:07:39,930 --> 00:07:44,100
we can do that by again typing in git add test.txt,

208
00:07:44,100 --> 00:07:46,410
which says I'm happy with my changes in this file,

209
00:07:46,410 --> 00:07:48,690
I want it to go to the master branch.

210
00:07:48,690 --> 00:07:49,860
Now that I've done that,

211
00:07:49,860 --> 00:07:53,677
I'm going to go ahead and type in git commit -m

212
00:07:53,677 --> 00:07:58,677
"Revision 1 - Added new line to the python script".

213
00:07:59,760 --> 00:08:00,870
And then hit Enter.

214
00:08:00,870 --> 00:08:02,460
And you can see there, we've added the new line

215
00:08:02,460 --> 00:08:04,320
to the Python script with Revision 1,

216
00:08:04,320 --> 00:08:05,340
one file was changed,

217
00:08:05,340 --> 00:08:07,860
and there was two insertions and one deletion.

218
00:08:07,860 --> 00:08:11,790
So now if we go ahead and do a git status again,

219
00:08:11,790 --> 00:08:14,040
we should expect that we have a clean branch,

220
00:08:14,040 --> 00:08:16,860
and we do because we committed all of our changes.

221
00:08:16,860 --> 00:08:20,760
So at this point, we now know how to put files in and out.

222
00:08:20,760 --> 00:08:23,670
And if you notice here, we still have our test.txt file

223
00:08:23,670 --> 00:08:25,560
and all the changes have been synced.

224
00:08:25,560 --> 00:08:27,060
The last thing I want to show you

225
00:08:27,060 --> 00:08:29,340
is that you can use Git and look at the Git log

226
00:08:29,340 --> 00:08:31,050
by typing in git log.

227
00:08:31,050 --> 00:08:33,210
And here it will show you everything that's ever happened

228
00:08:33,210 --> 00:08:35,520
inside of your Git repository.

229
00:08:35,520 --> 00:08:38,760
Now note, it will always show you the latest thing first

230
00:08:38,760 --> 00:08:40,230
and the oldest thing last.

231
00:08:40,230 --> 00:08:42,480
So if you're reading from top to bottom,

232
00:08:42,480 --> 00:08:45,240
you will see that this is the head or master branch.

233
00:08:45,240 --> 00:08:46,650
And in that head or master branch,

234
00:08:46,650 --> 00:08:50,100
the last commit we did was 244,

235
00:08:50,100 --> 00:08:52,200
and you could see that we added a new line

236
00:08:52,200 --> 00:08:53,310
to the Python script.

237
00:08:53,310 --> 00:08:55,350
Before that, we had our initial commit,

238
00:08:55,350 --> 00:08:57,030
and you'll see that on the bottom half.

239
00:08:57,030 --> 00:08:59,790
And that's the way Git works at a very basic level.

240
00:08:59,790 --> 00:09:02,760
By adding files, removing files, committing files,

241
00:09:02,760 --> 00:09:05,040
checking your status, and checking your logs,

242
00:09:05,040 --> 00:09:07,350
you can know what files are in your Git repository,

243
00:09:07,350 --> 00:09:08,460
you can have them tracked,

244
00:09:08,460 --> 00:09:10,200
and any changes will be notified to you

245
00:09:10,200 --> 00:09:12,420
and anybody else who's working on this project

246
00:09:12,420 --> 00:09:14,373
and using the same Git repository.

