1
00:00:00,000 --> 00:00:04,408
[MUSIC]

2
00:00:04,408 --> 00:00:08,754
Let us now explore some basic Git
commands that are very useful for

3
00:00:08,754 --> 00:00:10,660
us in this specialization.

4
00:00:11,670 --> 00:00:15,760
There's a lot more to get than
what we cover in this exercise.

5
00:00:18,167 --> 00:00:23,407
To get started go to a convenient
location on your computer and

6
00:00:23,407 --> 00:00:26,745
then create a folder named git-test.

7
00:00:30,340 --> 00:00:34,600
Then, open this folder
in your favorite editor.

8
00:00:38,190 --> 00:00:43,170
Here, I have the git-test folder
that we just created open

9
00:00:43,170 --> 00:00:45,390
in my VIsual Studio code.

10
00:00:45,390 --> 00:00:49,257
Let me add a file to this

11
00:00:49,257 --> 00:00:54,148
folder named index.html.

12
00:00:54,148 --> 00:00:59,990
Now you can see that I have added in some
HTML code into this index toward HTML5.

13
00:00:59,990 --> 00:01:02,580
Let's save the changes.

14
00:01:02,580 --> 00:01:05,240
Now let's switch to our command line.

15
00:01:06,740 --> 00:01:11,320
At the command line,
go to the git-test folder and

16
00:01:11,320 --> 00:01:15,860
let's initialize this folder
to be a git repository.

17
00:01:15,860 --> 00:01:19,800
So to do that, at the command line,
type git init.

18
00:01:21,620 --> 00:01:26,020
Now this folder has been
initialized to be a git repository.

19
00:01:27,170 --> 00:01:32,650
This is our first git command
that we have learned, git init.

20
00:01:32,650 --> 00:01:36,320
This intializes the current
folder as a git repository and

21
00:01:36,320 --> 00:01:42,380
when it initializes the folder,
it will mark that folder as a master.

22
00:01:42,380 --> 00:01:45,690
This is the master branch for my git.

23
00:01:45,690 --> 00:01:48,210
Now let's not worry about branches and
so on.

24
00:01:48,210 --> 00:01:51,000
We will not deal with that in this course.

25
00:01:51,000 --> 00:01:56,240
We will only be working with the master
branch in this particular specialization.

26
00:01:56,240 --> 00:01:58,500
So this would be marked as a master.

27
00:01:58,500 --> 00:02:02,060
Now this is the initial
point of our repository.

28
00:02:03,770 --> 00:02:08,410
The next command that we're
going to look at is git status.

29
00:02:08,410 --> 00:02:10,510
If you type git status
in the command line,

30
00:02:10,510 --> 00:02:13,740
it'll tell you the current
status of the folder.

31
00:02:13,740 --> 00:02:17,460
So let's do that at the command line and
see what it shows.

32
00:02:19,470 --> 00:02:23,395
At the command line, type git status and

33
00:02:23,395 --> 00:02:28,945
read the information that is
tracked out on the command window.

34
00:02:28,945 --> 00:02:31,235
You see that it says on branch master.

35
00:02:31,235 --> 00:02:35,200
So, that is the master branch
that we are on and it says,

36
00:02:35,200 --> 00:02:40,690
untracked files, and
then shows index.html in red.

37
00:02:40,690 --> 00:02:43,790
On your specific computer,
it may be using different colors or

38
00:02:43,790 --> 00:02:49,040
represent this differently, but
this is what it shows in my Mac.

39
00:02:49,040 --> 00:02:53,775
So now, this index.html file that
we have just created in this folder

40
00:02:53,775 --> 00:02:58,100
is now not been added
to our git repository.

41
00:02:58,100 --> 00:03:01,680
So let's go ahead and
add that file to the git repository.

42
00:03:01,680 --> 00:03:06,740
So to do that we say git add and
you can simply say

43
00:03:06,740 --> 00:03:12,350
dot which means that all the files in
the current directory will be added to

44
00:03:12,350 --> 00:03:17,680
what is called the staging
area of my git repository.

45
00:03:17,680 --> 00:03:21,740
So now if I again type git status,

46
00:03:21,740 --> 00:03:27,780
you will see that the file
index.html is marked in green.

47
00:03:27,780 --> 00:03:35,130
And it says changes to be committed there,
and then shows the filename.

48
00:03:35,130 --> 00:03:39,000
And then, so that means that this
file is ready to be committed to my

49
00:03:39,000 --> 00:03:39,830
git repository.

50
00:03:41,700 --> 00:03:46,100
So the next command that
we saw was git add,

51
00:03:46,100 --> 00:03:51,190
by using git add you can add file or
folders to that staging area.

52
00:03:51,190 --> 00:03:57,250
So once you add it to the staging area,
then you can commit that snapshot

53
00:03:57,250 --> 00:04:03,100
of our folder status
to our git repository.

54
00:04:03,100 --> 00:04:06,460
So that means that when
you do that git commit.

55
00:04:08,130 --> 00:04:12,610
What this command will
do is commit the current

56
00:04:12,610 --> 00:04:17,200
state of our folders
into our git repository.

57
00:04:17,200 --> 00:04:20,380
So all the files,
as they exist at the moment,

58
00:04:20,380 --> 00:04:24,570
once they have been stages using the git
add, then they will be committed to

59
00:04:24,570 --> 00:04:29,510
our git repository when we
execute the git command folder.

60
00:04:29,510 --> 00:04:34,650
So on this point, when we execute
the git command, then our initial

61
00:04:34,650 --> 00:04:40,750
state will now be changed to the first
commit to the git repository.

62
00:04:40,750 --> 00:04:42,650
So let's go ahead and do that.

63
00:04:45,470 --> 00:04:49,460
Back at the command prompt, let's type,

64
00:04:49,460 --> 00:04:54,880
git commit and then we can ever
add a message to our commit.

65
00:04:54,880 --> 00:05:00,520
So I am going to say git
commit -m first commit,

66
00:05:00,520 --> 00:05:04,160
because this is our first
commit to our git repository.

67
00:05:04,160 --> 00:05:10,630
So, when I do that, it says, okay one file
has been added to the git repository and

68
00:05:10,630 --> 00:05:15,300
some other information will be
typed out onto that command window.

69
00:05:15,300 --> 00:05:20,440
So let's now check again, git status.

70
00:05:20,440 --> 00:05:26,220
And now you see that it says nothing
to commit, working directory is clean.

71
00:05:26,220 --> 00:05:31,230
So what that means is that the current
state of my working directory, or

72
00:05:31,230 --> 00:05:35,860
working folder,
has been committed to the git repository.

73
00:05:35,860 --> 00:05:39,330
So a snapshot has been
committed to my git repository.

74
00:05:39,330 --> 00:05:46,851
Now I can type the next command
called git log --oneline.

75
00:05:46,851 --> 00:05:53,020
And see that it shows a number there,
an eight digit number there.

76
00:05:53,020 --> 00:05:57,850
And then also shows the message that we
put in to our commit, saying first commit.

77
00:05:57,850 --> 00:06:03,340
So that is the log of all the commits that
have been put into my data repository.

78
00:06:05,120 --> 00:06:13,832
So going back to our next git command we
saw that git log --oneline we'll see and

79
00:06:13,832 --> 00:06:18,540
it shows us a brief log
of all the commits.

80
00:06:18,540 --> 00:06:23,920
If you simply type git log it display
a lot more detail information about

81
00:06:23,920 --> 00:06:26,220
all the commits.

82
00:06:26,220 --> 00:06:30,850
But this is sufficient enough for
obtaining information that we require.

83
00:06:33,350 --> 00:06:40,820
Let's now come back to our editor
here in Visual Studio code.

84
00:06:40,820 --> 00:06:44,940
So I'm going to add more
changes to my index.html file.

85
00:06:44,940 --> 00:06:45,945
So I will add.

86
00:06:54,298 --> 00:06:57,790
So I have changed my index.html file.

87
00:06:57,790 --> 00:07:01,750
Now let me add another folder
under the GIT-TEST folder.

88
00:07:01,750 --> 00:07:07,220
So I will create a subfolder
here named templates, and

89
00:07:07,220 --> 00:07:13,450
inside this templates folder, I'm going to
create another file named test.html.

90
00:07:13,450 --> 00:07:17,180
This is just to show
you how git can commit

91
00:07:17,180 --> 00:07:21,120
entire folder hierarchy
into its repository.

92
00:07:21,120 --> 00:07:24,754
So with test.html now there,

93
00:07:24,754 --> 00:07:31,185
I'm just going to copy
everything from my index.html

94
00:07:31,185 --> 00:07:36,374
into my test.html, and save the changes.

95
00:07:39,447 --> 00:07:41,484
Going back to the command line,

96
00:07:41,484 --> 00:07:45,943
let's now check out the status of
our git repository and this folder.

97
00:07:45,943 --> 00:07:52,880
So typing git status
shows that the index.html

98
00:07:52,880 --> 00:07:57,370
file that we have already added earlier
to the repository has now been modified.

99
00:07:57,370 --> 00:08:00,207
So if there is a new version
of the index index.html file.

100
00:08:00,207 --> 00:08:04,011
Also it shows that there
are some untracked files in

101
00:08:04,011 --> 00:08:06,408
this folder called templates.

102
00:08:06,408 --> 00:08:11,530
Let's add all these changes to our
repository, to the staging area.

103
00:08:11,530 --> 00:08:16,640
So again type git add dot and
then all these

104
00:08:16,640 --> 00:08:21,620
files will be added to the staging area.

105
00:08:21,620 --> 00:08:23,940
Again, checking out the status,

106
00:08:23,940 --> 00:08:29,490
you now see that the changes that
I've been added to the staging area.

107
00:08:29,490 --> 00:08:32,850
So all these files have been
added to the staging area.

108
00:08:32,850 --> 00:08:34,560
Let's do one more commit.

109
00:08:34,560 --> 00:08:38,381
So I would say git commit -m.

110
00:08:40,218 --> 00:08:47,234
Second commit and
then let's check out the log.

111
00:08:50,828 --> 00:08:57,480
If you check out the log you now see that
there two commits in my git repository.

112
00:08:57,480 --> 00:08:59,130
The first and the second commit and

113
00:08:59,130 --> 00:09:03,040
note that each one of them is
given a different number there.

114
00:09:03,040 --> 00:09:09,830
If you want to see the full details of
the log, you can type simply git log and

115
00:09:09,830 --> 00:09:15,095
then you will see more details in there
then what you would be interested in.

116
00:09:15,095 --> 00:09:19,115
So notice that the oneline commit

117
00:09:19,115 --> 00:09:24,405
only gives the first few characters
of my commit number there.

118
00:09:24,405 --> 00:09:26,395
That is sufficient enough for
us to operate with.

119
00:09:29,245 --> 00:09:35,502
Let me now go back again to my
Visual Studio and to add one more.

120
00:09:44,019 --> 00:09:45,890
One more line to my index.html file.

121
00:09:47,140 --> 00:09:49,800
So now my index.html
file has been modified.

122
00:09:51,660 --> 00:09:53,123
And let's save the changes.

123
00:09:55,099 --> 00:09:57,871
Going back to the command line,

124
00:09:57,871 --> 00:10:04,304
go in git status shows that
the index.html file has been modified.

125
00:10:04,304 --> 00:10:10,650
So let's add this to staging area and
then do a third commit.

126
00:10:10,650 --> 00:10:18,720
So let's say git add dot git status.

127
00:10:18,720 --> 00:10:22,487
Now you see that the index.html,
the modified version has been added.

128
00:10:22,487 --> 00:10:26,240
Now we can say git commit.

129
00:10:31,176 --> 00:10:37,084
Third commit.

130
00:10:37,084 --> 00:10:43,810
And git log oneline, and you'll see that
there are three commits in our repository.

131
00:10:43,810 --> 00:10:48,220
So now our repository contains
snapshots of three different types.

132
00:10:48,220 --> 00:10:51,468
At the end of the first commit,
at the end of the second commit, and

133
00:10:51,468 --> 00:10:52,985
at the end of the third commit.

134
00:10:52,985 --> 00:10:56,842
Now we also can roll back changes.

135
00:10:56,842 --> 00:11:01,590
We can revert the repository
to a previous version.

136
00:11:01,590 --> 00:11:04,780
We can pull out a file out
from an older commit and

137
00:11:04,780 --> 00:11:09,180
then ripple this existing file in
our directly from the older commit.

138
00:11:09,180 --> 00:11:14,120
So let’s see how we can operate with these
things by learning a couple more commands.

139
00:11:15,820 --> 00:11:21,450
At this stage, our index.HTML
file is in the current state.

140
00:11:21,450 --> 00:11:24,795
So you can notice that it has an h1 and
two p's.

141
00:11:26,530 --> 00:11:29,365
Let's now look at the next git command.

142
00:11:30,815 --> 00:11:36,185
The next git command that we're
going to learn about is git checkout.

143
00:11:36,185 --> 00:11:40,300
So this checkout command
allows us to checkout a file

144
00:11:40,300 --> 00:11:44,040
from a previous commit
in our git repository.

145
00:11:44,040 --> 00:11:48,050
So if we don't like the current
file that we have in our folder and

146
00:11:48,050 --> 00:11:51,160
we will want to go back to
a previous version of the file,

147
00:11:51,160 --> 00:11:55,090
we can always check out the file
from a previous commit, or

148
00:11:55,090 --> 00:12:00,230
from the current commit and
then continue to work with that file.

149
00:12:00,230 --> 00:12:07,136
So let's make use of this and see some
folder changes to our git repository.

150
00:12:09,137 --> 00:12:15,346
Going back to our command line,
we remember that between the second and

151
00:12:15,346 --> 00:12:20,235
the third commit I made
changes to my index.html file.

152
00:12:20,235 --> 00:12:25,526
Suppose I want to revert back to
the index.html file from my second commit.

153
00:12:25,526 --> 00:12:33,951
So then I can simply say
git checkout 900cfcf.

154
00:12:33,951 --> 00:12:40,980
So that is commit identifier, the number
that identifies that particular comment.

155
00:12:40,980 --> 00:12:46,170
And then I can say, index.html and
what you would notice

156
00:12:46,170 --> 00:12:53,430
is the back older file will now be checked
up into my current working directory.

157
00:12:55,919 --> 00:12:58,043
Going to my Visual Studio code,

158
00:12:58,043 --> 00:13:03,340
you now notice that my index.html file
has reverted to the previous version.

159
00:13:03,340 --> 00:13:07,936
So the change that made before
the third commit is now gone.

160
00:13:07,936 --> 00:13:13,123
So my index.html file has been restored to

161
00:13:13,123 --> 00:13:18,750
it's a state at the end
of the second comment.

162
00:13:18,750 --> 00:13:24,863
Now at the command line
if I type git status.

163
00:13:24,863 --> 00:13:29,140
You'll notice like this index.html file.

164
00:13:29,140 --> 00:13:33,520
Which has reverted to what it was
at the end of the second commit.

165
00:13:33,520 --> 00:13:37,710
It has now already been staged so
using the git checkout

166
00:13:38,720 --> 00:13:42,930
we'll pull out an older version
of the file and then replace what

167
00:13:42,930 --> 00:13:47,670
is in the current directory and then it
will also check it into the staging area.

168
00:13:48,970 --> 00:13:53,960
So now if I do that and then I realize
that this is what I want I can simply

169
00:13:53,960 --> 00:13:56,450
do another commit at this point.

170
00:13:56,450 --> 00:14:01,090
And then that file can be
commented as the fourth commit.

171
00:14:02,710 --> 00:14:08,035
But suppose I don't like this,
I want to revert back to that

172
00:14:08,035 --> 00:14:13,700
index.html file at the end
of the third commit.

173
00:14:13,700 --> 00:14:21,788
Then all I can do is
say git reset HEAD and

174
00:14:21,788 --> 00:14:27,404
index.html.

175
00:14:27,404 --> 00:14:31,821
So at this point what happens
is that the index.html,

176
00:14:31,821 --> 00:14:36,780
the modified version that I
check out is still there.

177
00:14:36,780 --> 00:14:41,275
But this file has been unstaged
from the staging area.

178
00:14:43,650 --> 00:14:49,269
If you go back and
look at the index.html in your editor,

179
00:14:49,269 --> 00:14:54,887
it will still show the stage at
the end of the second commit

180
00:14:54,887 --> 00:15:01,250
because we had pull down that
file using check out for that.

181
00:15:01,250 --> 00:15:06,072
Now if you want to revert it back to what
it was at the end of the third commit

182
00:15:06,072 --> 00:15:09,490
then we do one more check
out from the third commit.

183
00:15:10,540 --> 00:15:18,900
Going to our command
window type git status and

184
00:15:18,900 --> 00:15:24,580
you would notice that the index.html
is marked as modified, but

185
00:15:24,580 --> 00:15:31,040
it also shows this particular statement
here, it says git checkout --

186
00:15:31,040 --> 00:15:35,270
and the file link to discard
the changes in the working directory.

187
00:15:35,270 --> 00:15:38,150
So that's one way you can
discard the changes that you

188
00:15:38,150 --> 00:15:43,095
don't need to a particular file
corresponding to the previous commit.

189
00:15:43,095 --> 00:15:45,595
So let me restore this index.html back

190
00:15:45,595 --> 00:15:48,205
to what it was at the end
of the third commit.

191
00:15:48,205 --> 00:15:53,104
So to do that I will simply say git

192
00:15:53,104 --> 00:15:57,647
checkout -- index.html.

193
00:15:57,647 --> 00:16:04,278
And then, if I do git status it shows
that my directory is clean and, basically

194
00:16:04,278 --> 00:16:10,520
my directory had been restored to
the state of the end of the third commit.

195
00:16:12,370 --> 00:16:17,580
Going to the file in my
Visual Studio code I see that

196
00:16:17,580 --> 00:16:21,060
the file has been restored back to what
it was at the end of the third commit.

197
00:16:21,060 --> 00:16:25,840
So this is one way you can, if you've made
changes to a file after the commit and

198
00:16:25,840 --> 00:16:28,700
you want to just discard
those changes you can simply

199
00:16:28,700 --> 00:16:30,880
check out the file from the last commit.

200
00:16:30,880 --> 00:16:34,530
And then all your changes that
you've done after the last commit

201
00:16:34,530 --> 00:16:36,220
will be discarded on the spot.

202
00:16:36,220 --> 00:16:40,960
So these are some basic commands
that are very useful for

203
00:16:40,960 --> 00:16:44,510
you as you go to the courses
in this specialization,

204
00:16:44,510 --> 00:16:49,160
because you may want to commit
at the end of each exercise.

205
00:16:49,160 --> 00:16:56,220
And as you proceed forward you would
still have a committed version of

206
00:16:56,220 --> 00:17:01,790
the state of your folder at
the end of the previous exercise.

207
00:17:01,790 --> 00:17:06,920
So that way if you are getting out a new
exercise and you discovered that you

208
00:17:06,920 --> 00:17:11,803
had made mistakes and you want to
revert back to the previous commit you

209
00:17:11,803 --> 00:17:18,010
always have a way of doing that using
the commands that we have just learned.

210
00:17:18,010 --> 00:17:24,430
So with this basic understanding
of these few git commands,

211
00:17:24,430 --> 00:17:29,260
we will be able to proceed
forward with understanding and

212
00:17:29,260 --> 00:17:33,570
using git in the courses
of this specialization.

213
00:17:35,560 --> 00:17:41,260
So now, we have review the git reset for
specific file or git reset

214
00:17:41,260 --> 00:17:47,970
in generally if you simply type git reset
it'll restore you back to the last commit.

215
00:17:47,970 --> 00:17:51,360
So it would reset the staging
area to the last commit

216
00:17:51,360 --> 00:17:55,270
without disturbing the changes that you
have done to your working directory.

217
00:17:55,270 --> 00:17:58,390
So once you reset, then you can check out

218
00:17:58,390 --> 00:18:02,140
the previous version of the file that you
have committed in the previous commit.

219
00:18:02,140 --> 00:18:07,380
So this way you can restore your
folder back to where you were at

220
00:18:07,380 --> 00:18:10,450
the starting point of the previous commit.

221
00:18:10,450 --> 00:18:15,010
So sometimes when you are going an
exercise and you realize you made mistake

222
00:18:15,010 --> 00:18:20,360
you always have a way of reverting
back to a previous version.

223
00:18:20,360 --> 00:18:25,665
So with this commands,
I think you're all set to use git in

224
00:18:25,665 --> 00:18:31,111
the courses of this specialization So

225
00:18:31,111 --> 00:18:34,276
at the end of this exercise,
did you Git it?

226
00:18:34,276 --> 00:18:37,459
[MUSIC]