1
00:00:02,110 --> 00:00:05,630
So we are able to save different snapshots,

2
00:00:05,630 --> 00:00:06,840
different commits,

3
00:00:06,840 --> 00:00:09,760
and by initializing a good repository,

4
00:00:09,760 --> 00:00:14,020
these commits are all part of a so-called branch.

5
00:00:14,020 --> 00:00:15,300
In our case here,

6
00:00:15,300 --> 00:00:19,720
the default branch is the so-called master branch.

7
00:00:19,720 --> 00:00:21,170
How can we see this?

8
00:00:21,170 --> 00:00:23,720
Well, first by running "git status",

9
00:00:23,720 --> 00:00:26,530
once again we know this command already.

10
00:00:26,530 --> 00:00:30,240
There you'll see that we are on the branch master here.

11
00:00:30,240 --> 00:00:31,400
And besides that,

12
00:00:31,400 --> 00:00:35,540
we also have a command which lists all the branches inside

13
00:00:35,540 --> 00:00:36,910
our Git project.

14
00:00:36,910 --> 00:00:39,897
And this command is simply "git branch".

15
00:00:40,940 --> 00:00:44,490
Git branch here doesn't show us well, too much information.

16
00:00:44,490 --> 00:00:46,980
We have one branch only.

17
00:00:46,980 --> 00:00:49,760
And currently we are in this branch.

18
00:00:49,760 --> 00:00:52,090
This is indicated by the green color here

19
00:00:52,090 --> 00:00:55,163
and by this asterisk ahead of the branch name.

20
00:00:56,180 --> 00:00:58,940
As we saw it, when running Git in it,

21
00:00:58,940 --> 00:01:03,270
we also have the ability to rename a branch.

22
00:01:03,270 --> 00:01:05,140
Typically and historically,

23
00:01:05,140 --> 00:01:09,950
the default branch inside a Git project was named "master".

24
00:01:09,950 --> 00:01:13,150
In the last months and years, this changed.

25
00:01:13,150 --> 00:01:17,890
Nowadays, we typically also use "main" instead of "master".

26
00:01:17,890 --> 00:01:19,750
We can of course change the name,

27
00:01:19,750 --> 00:01:21,570
we'll do this in a few seconds.

28
00:01:21,570 --> 00:01:24,920
It's just important to keep in mind that this master

29
00:01:24,920 --> 00:01:27,870
or main branch, typically is the branch

30
00:01:27,870 --> 00:01:31,550
holding your main code, your working code.

31
00:01:31,550 --> 00:01:32,650
For example,

32
00:01:32,650 --> 00:01:35,870
the code you use for your currently running website,

33
00:01:35,870 --> 00:01:36,870
for example.

34
00:01:36,870 --> 00:01:39,020
If you want to implement new features,

35
00:01:39,020 --> 00:01:41,960
you create new branches, work on that feature.

36
00:01:41,960 --> 00:01:42,900
Once you're done,

37
00:01:42,900 --> 00:01:45,980
you add these changes to the master branch.

38
00:01:45,980 --> 00:01:48,740
We'll of course have a look at this flow in this lecture.

39
00:01:48,740 --> 00:01:52,310
I just wanted to give you some insights already,

40
00:01:52,310 --> 00:01:55,160
what is going to happen to get a better idea

41
00:01:55,160 --> 00:01:57,693
of this branch concept immediately.

42
00:01:58,560 --> 00:02:02,280
Let's get started by renaming this branch, tho.

43
00:02:02,280 --> 00:02:05,850
Currently, we are inside the branch that we want to rename.

44
00:02:05,850 --> 00:02:08,030
So the master branch in our case,

45
00:02:08,030 --> 00:02:11,930
and if we now run "git branch -m",

46
00:02:11,930 --> 00:02:13,720
and now add the new name

47
00:02:13,720 --> 00:02:15,470
that we want to use for this branch,

48
00:02:15,470 --> 00:02:17,760
in our case, this could be "main".

49
00:02:17,760 --> 00:02:21,770
Well, by doing this, you get no confirmation at all,

50
00:02:21,770 --> 00:02:24,720
but if you then run "git branch",

51
00:02:24,720 --> 00:02:28,370
you'll see that "master" now changed to "main".

52
00:02:28,370 --> 00:02:31,250
This didn't have any kind of impact on through commits

53
00:02:31,250 --> 00:02:32,560
inside this branch.

54
00:02:32,560 --> 00:02:34,923
It was just a plain renaming.

55
00:02:36,020 --> 00:02:39,810
Now let's say that this content of this main branch here

56
00:02:39,810 --> 00:02:41,670
is exactly what you want to have.

57
00:02:41,670 --> 00:02:43,970
So you want to have this test or text file

58
00:02:43,970 --> 00:02:45,220
and the second commit,

59
00:02:45,220 --> 00:02:48,800
and now we want to add, well, additional data,

60
00:02:48,800 --> 00:02:51,600
but not immediately into this main branch.

61
00:02:51,600 --> 00:02:55,520
We first want to add this data, write some code,

62
00:02:55,520 --> 00:02:56,530
test the code.

63
00:02:56,530 --> 00:03:00,000
And then once it's done, we want to implement this code

64
00:03:00,000 --> 00:03:03,873
into this main branch, into our main project, so to say.

65
00:03:04,730 --> 00:03:07,660
What we need for this is a new branch.

66
00:03:07,660 --> 00:03:09,980
And to create new branches in Git,

67
00:03:09,980 --> 00:03:12,220
we have a, well, command obviously,

68
00:03:12,220 --> 00:03:16,210
and this command is called "git checkout".

69
00:03:16,210 --> 00:03:19,770
Checkout here simply means we refer to another branch.

70
00:03:19,770 --> 00:03:23,310
Checkout can also be used to switch between branches.

71
00:03:23,310 --> 00:03:26,680
In our case, not possible as we only have a single branch

72
00:03:26,680 --> 00:03:28,460
only at the moment.

73
00:03:28,460 --> 00:03:29,547
And now with " -b",

74
00:03:30,390 --> 00:03:33,460
this simply means that we want to check out a new branch

75
00:03:33,460 --> 00:03:36,990
and create a new branch based on the branch

76
00:03:36,990 --> 00:03:38,340
we are currently in.

77
00:03:38,340 --> 00:03:40,620
So based on our main branch here,

78
00:03:40,620 --> 00:03:42,980
and now we can give this branch a name.

79
00:03:42,980 --> 00:03:45,710
There is no strict naming convention here.

80
00:03:45,710 --> 00:03:48,540
In my case, I'll simply call it "feature",

81
00:03:48,540 --> 00:03:51,470
as this branch will add a new feature

82
00:03:51,470 --> 00:03:54,040
to our main branch in the end.

83
00:03:54,040 --> 00:03:57,000
With this command, you get the confirmation

84
00:03:57,000 --> 00:04:00,800
that we switched to a new branch, named "feature"

85
00:04:00,800 --> 00:04:03,163
and by running "git branch" now,

86
00:04:04,800 --> 00:04:08,280
you'll see that we are already in this feature branch.

87
00:04:08,280 --> 00:04:12,120
Again, indicated by the green color and that asterisk.

88
00:04:12,120 --> 00:04:16,240
And if we check the commits inside this feature branch

89
00:04:16,240 --> 00:04:18,177
with "git log",

90
00:04:20,209 --> 00:04:22,660
well, you see no difference, right?

91
00:04:22,660 --> 00:04:24,870
We are still having the same commits

92
00:04:24,870 --> 00:04:27,040
that we had in the main branch,

93
00:04:27,040 --> 00:04:29,350
and you also get the information up here that,

94
00:04:29,350 --> 00:04:30,250
well basically,

95
00:04:30,250 --> 00:04:33,600
this commit with this ID is the head.

96
00:04:33,600 --> 00:04:36,010
The head is so to say the latest commit

97
00:04:36,010 --> 00:04:37,520
of a specific branch.

98
00:04:37,520 --> 00:04:40,540
So this commit is the head of both the feature

99
00:04:40,540 --> 00:04:41,823
and the main branch.

100
00:04:42,720 --> 00:04:45,970
With this now we can work on code as I said,

101
00:04:45,970 --> 00:04:48,590
that we might want to implement in this feature branch.

102
00:04:48,590 --> 00:04:51,210
Here I'll keep things simple again,

103
00:04:51,210 --> 00:04:53,860
as this module is just about understanding

104
00:04:53,860 --> 00:04:55,980
how Git generally works.

105
00:04:55,980 --> 00:05:00,077
Therefore we could create a new folder and let's say,

106
00:05:00,077 --> 00:05:02,523
"new feature", for example.

107
00:05:03,500 --> 00:05:08,500
And in there, we simply add the "feature.txt" file.

108
00:05:08,550 --> 00:05:11,230
So this is content that we now only have

109
00:05:11,230 --> 00:05:13,070
in our feature branch.

110
00:05:13,070 --> 00:05:16,343
So if you now run "git status" once again,

111
00:05:18,090 --> 00:05:20,600
you see we are on the feature branch,

112
00:05:20,600 --> 00:05:23,490
that's important, and we have untracked files.

113
00:05:23,490 --> 00:05:26,390
So we basically have this new feature folder and all the

114
00:05:26,390 --> 00:05:28,220
files it contains.

115
00:05:28,220 --> 00:05:32,463
Therefore, we can now run again "git add . "

116
00:05:33,590 --> 00:05:36,650
to add all newly added files

117
00:05:36,650 --> 00:05:39,450
and changes made to tracked files.

118
00:05:39,450 --> 00:05:41,010
And now we commit this change

119
00:05:41,010 --> 00:05:46,010
with "git commit -m "added mew feature"".

120
00:05:48,640 --> 00:05:52,460
Like this, the commit was successful.

121
00:05:52,460 --> 00:05:55,490
If we check our log, once again,

122
00:05:55,490 --> 00:06:00,060
you see we have three commits now in our feature branch,

123
00:06:00,060 --> 00:06:02,940
but only two commits in our main branch.

124
00:06:02,940 --> 00:06:04,830
You can again see this by this head.

125
00:06:04,830 --> 00:06:08,060
So here, the latest commit is in the feature branch,

126
00:06:08,060 --> 00:06:09,210
this one here.

127
00:06:09,210 --> 00:06:10,710
Whereas the second commit,

128
00:06:10,710 --> 00:06:12,640
so this one we created earlier,

129
00:06:12,640 --> 00:06:15,680
is part of the main branch only.

130
00:06:15,680 --> 00:06:16,860
And now the question is,

131
00:06:16,860 --> 00:06:19,970
how can we bring these changes together?

132
00:06:19,970 --> 00:06:21,910
How can we add this feature,

133
00:06:21,910 --> 00:06:26,610
this commit added in the feature branch, to our main branch?

134
00:06:26,610 --> 00:06:30,033
Well, for this, we first leave our log with Q once again,

135
00:06:30,910 --> 00:06:35,120
and then we have to merge the two branches.

136
00:06:35,120 --> 00:06:37,810
Merging branches simply means you combine

137
00:06:37,810 --> 00:06:40,060
the two commits of these branches.

138
00:06:40,060 --> 00:06:43,050
Well, to have a merged branch with all the code

139
00:06:43,050 --> 00:06:46,770
implemented or incorporated in this branch.

140
00:06:46,770 --> 00:06:49,017
Merging always works from a

141
00:06:49,017 --> 00:06:52,810
"I am currently in a branch that should receive

142
00:06:52,810 --> 00:06:55,350
additional commits", way of thinking.

143
00:06:55,350 --> 00:06:56,270
So in our case,

144
00:06:56,270 --> 00:07:00,240
this means that if we want to add the feature that we just

145
00:07:00,240 --> 00:07:03,670
edit in the feature branch to our master branch,

146
00:07:03,670 --> 00:07:06,810
we have to switch to the master branch first

147
00:07:06,810 --> 00:07:11,410
and then merge the feature branch into the master branch.

148
00:07:11,410 --> 00:07:15,550
To do that, we should check out our master branch therefore,

149
00:07:15,550 --> 00:07:17,787
so "git checkout master",

150
00:07:18,740 --> 00:07:21,460
which doesn't work as we renamed it to "main".

151
00:07:21,460 --> 00:07:22,680
So, my bad here.

152
00:07:22,680 --> 00:07:26,110
So we should of course refer to the main branch.

153
00:07:26,110 --> 00:07:27,420
Here we are.

154
00:07:27,420 --> 00:07:31,680
Now, you'll see in our git log that inside the main branch

155
00:07:31,680 --> 00:07:33,523
we only have these two commits.

156
00:07:35,370 --> 00:07:39,690
But, by now running "git merge",

157
00:07:39,690 --> 00:07:44,160
and now referring to the branch that contains the commits

158
00:07:44,160 --> 00:07:47,230
that should be merged into our main branch here,

159
00:07:47,230 --> 00:07:49,410
so we run "git merge feature".

160
00:07:49,410 --> 00:07:52,190
So the branch name of the other branch.

161
00:07:52,190 --> 00:07:55,420
Well, if we do that, you see that now,

162
00:07:55,420 --> 00:07:58,660
although we are still in the master branch,

163
00:07:58,660 --> 00:08:00,690
we have this new feature folder

164
00:08:00,690 --> 00:08:04,890
an alternate text file added into this branch.

165
00:08:04,890 --> 00:08:07,057
And by again running "git log",

166
00:08:08,070 --> 00:08:11,210
this, you see that now again,

167
00:08:11,210 --> 00:08:15,510
both branches here main and feature are the so-called head,

168
00:08:15,510 --> 00:08:16,900
so in simple words,

169
00:08:16,900 --> 00:08:19,620
the latest commit of the branches,

170
00:08:19,620 --> 00:08:21,250
and therefore this feature

171
00:08:21,250 --> 00:08:25,490
is now available while also in this main branch.

172
00:08:25,490 --> 00:08:28,120
So this was a successful merge,

173
00:08:28,120 --> 00:08:31,110
but what happens if we accidentally work

174
00:08:31,110 --> 00:08:34,900
on the same code section, on the same code snapshot

175
00:08:34,900 --> 00:08:38,559
in the same file and then we try to run such a merge?

176
00:08:38,559 --> 00:08:40,530
This would obviously lead to a conflict

177
00:08:40,530 --> 00:08:43,700
because we have changes applied to the same well,

178
00:08:43,700 --> 00:08:45,710
position so to say in our code,

179
00:08:45,710 --> 00:08:49,020
and then we have to decide, well, which change wins.

180
00:08:49,020 --> 00:08:50,863
So which change should be kept.

181
00:08:51,720 --> 00:08:53,790
We are currently in the master branch,

182
00:08:53,790 --> 00:08:58,790
therefore we could go to our "test.txt" file.

183
00:08:59,920 --> 00:09:02,160
And we could say that we, don't call this.

184
00:09:02,160 --> 00:09:03,210
This is my first commit.

185
00:09:03,210 --> 00:09:08,210
But this is another commit here, right? Like this.

186
00:09:09,770 --> 00:09:13,700
So we then add this and commit this change

187
00:09:13,700 --> 00:09:18,693
with a message of "updated test.txt" .

188
00:09:22,400 --> 00:09:23,290
So we did that.

189
00:09:23,290 --> 00:09:25,013
And if we now check our log,

190
00:09:26,840 --> 00:09:29,370
you see that we have well, a new commit in here,

191
00:09:29,370 --> 00:09:32,670
updated test.txt in our main branch,

192
00:09:32,670 --> 00:09:35,400
which doesn't affect the feature branch at the moment.

193
00:09:35,400 --> 00:09:37,840
So we can leave the log again

194
00:09:37,840 --> 00:09:40,433
and now check out the feature branch.

195
00:09:44,810 --> 00:09:46,630
Let me clear this.

196
00:09:46,630 --> 00:09:48,930
And here we still have the initial stage, right?

197
00:09:48,930 --> 00:09:50,630
So the unchanged text.

198
00:09:50,630 --> 00:09:52,517
And now we say, well,

199
00:09:52,517 --> 00:09:57,517
"this is again a commit", just to have a difference here.

200
00:09:59,320 --> 00:10:01,550
So we save this now.

201
00:10:01,550 --> 00:10:04,720
We also add this change to the staging area.

202
00:10:04,720 --> 00:10:08,410
We commit this change inside our feature branch,

203
00:10:08,410 --> 00:10:13,410
maybe with "changed test.txt content"

204
00:10:14,923 --> 00:10:17,870
to have a different message here.

205
00:10:17,870 --> 00:10:20,220
So we commit this. No problem here.

206
00:10:20,220 --> 00:10:22,833
If in a run, our git log once again,

207
00:10:25,100 --> 00:10:26,230
we see that this is all right.

208
00:10:26,230 --> 00:10:29,713
So feature branch has this latest commit we just added.

209
00:10:30,940 --> 00:10:34,973
And if we now, again, check out our master branch,

210
00:10:36,666 --> 00:10:39,120
and again, my bad, I'm sorry about this.

211
00:10:39,120 --> 00:10:40,810
I typically work with "master" still,

212
00:10:40,810 --> 00:10:43,630
therefore I'm not totally used to "main" here.

213
00:10:43,630 --> 00:10:45,547
So "git checkout main".

214
00:10:46,470 --> 00:10:47,830
Clear it.

215
00:10:47,830 --> 00:10:50,370
Now we again, run our merge command.

216
00:10:50,370 --> 00:10:53,760
So "git merge" and we merged a feature branch

217
00:10:53,760 --> 00:10:55,850
into our main or master branch.

218
00:10:55,850 --> 00:10:57,957
So "git merged feature".

219
00:10:59,450 --> 00:11:02,860
Then we see that we have well emerged conflict

220
00:11:03,770 --> 00:11:06,670
because we have a current change.

221
00:11:06,670 --> 00:11:09,320
This is the change we have in our current branch.

222
00:11:09,320 --> 00:11:10,153
So in our case,

223
00:11:10,153 --> 00:11:13,840
the main branch, and we have an incoming change.

224
00:11:13,840 --> 00:11:16,740
This is the change that we made in the feature branch.

225
00:11:16,740 --> 00:11:21,120
So the branch that we want to merge into this master branch,

226
00:11:21,120 --> 00:11:22,990
and therefore we have well,

227
00:11:22,990 --> 00:11:26,120
multiple options to fix this merge conflict.

228
00:11:26,120 --> 00:11:29,180
Visual studio code is a great help here, by the way.

229
00:11:29,180 --> 00:11:30,730
And well basically,

230
00:11:30,730 --> 00:11:33,620
the most common things we do is either compare the

231
00:11:33,620 --> 00:11:37,190
changes over here, or we accept the current change.

232
00:11:37,190 --> 00:11:41,010
So the change in our current branch or the incoming change.

233
00:11:41,010 --> 00:11:43,813
So as I said, the change from the feature branch here.

234
00:11:44,680 --> 00:11:47,660
If we accept that incoming change here, for example,

235
00:11:47,660 --> 00:11:49,670
we can simply click right here

236
00:11:49,670 --> 00:11:52,040
and then we see if we still have a warning.

237
00:11:52,040 --> 00:11:57,040
So, if we save this now and run "git status",

238
00:12:00,900 --> 00:12:03,430
you see we have unmerged paths because

239
00:12:03,430 --> 00:12:05,230
that was the problem that we have.

240
00:12:05,230 --> 00:12:07,890
But now with the accepted incoming change

241
00:12:07,890 --> 00:12:09,770
and saving the file,

242
00:12:09,770 --> 00:12:11,700
we need to create another commit.

243
00:12:11,700 --> 00:12:12,830
So let's run "git add",

244
00:12:12,830 --> 00:12:15,987
and let's now commit this change with a message of

245
00:12:15,987 --> 00:12:20,987
"merged text.txt from feature", for example,

246
00:12:24,910 --> 00:12:29,910
and with this, now clear this once again and run "git log".

247
00:12:32,390 --> 00:12:33,600
You see that in here,

248
00:12:33,600 --> 00:12:36,530
we now have the latest commit from the feature branch.

249
00:12:36,530 --> 00:12:39,110
So this is now part of our main branch.

250
00:12:39,110 --> 00:12:40,280
And additionally,

251
00:12:40,280 --> 00:12:41,770
we have that merge commit.

252
00:12:41,770 --> 00:12:44,400
So this is basically the commit that we just created

253
00:12:44,400 --> 00:12:46,860
that brought these two branches together

254
00:12:46,860 --> 00:12:51,510
without any conflicts as we just, well solved these.

255
00:12:51,510 --> 00:12:54,380
So, this is it about creating commits

256
00:12:54,380 --> 00:12:57,670
and creating branches and merging branches.

257
00:12:57,670 --> 00:13:01,680
Now, the next question is, how can we actually delete data?

258
00:13:01,680 --> 00:13:05,270
So delete commits, delete branches and so on.

259
00:13:05,270 --> 00:13:08,083
This is how we will continue in the next lecture.

