1
00:00:00,000 --> 00:00:10,600
In this video, you'll learn more about creating Git repositories.

2
00:00:10,600 --> 00:00:15,800
In order to show you the video, I need to start at a public Git environment.

3
00:00:15,800 --> 00:00:19,000
So I'm going to use GitHub to do so.

4
00:00:19,000 --> 00:00:22,719
In order to do something on GitHub, you need to have an account.

5
00:00:22,719 --> 00:00:28,360
So you sign up if you don't have an account yet, or you sign in if you want to sign in

6
00:00:28,360 --> 00:00:34,639
with your current account.

7
00:00:34,639 --> 00:00:37,400
This is bringing me to my Git environment.

8
00:00:37,400 --> 00:00:43,040
So I am going to use new to create a new Git repository.

9
00:00:43,040 --> 00:00:49,680
And in that new Git repository, I need to give it a name and the name is new Git repo.

10
00:00:49,680 --> 00:00:53,360
And there I can see that new Git repo is available.

11
00:00:53,360 --> 00:00:55,360
So I can choose what I want to do.

12
00:00:55,360 --> 00:00:59,119
So choose visibility, set to public, and that is okay.

13
00:00:59,119 --> 00:01:01,119
You can set private as well.

14
00:01:01,119 --> 00:01:06,800
And if you set the Git repo to private, well, then it's not accessible by everybody.

15
00:01:06,800 --> 00:01:08,160
And there are more options.

16
00:01:08,160 --> 00:01:10,400
I will ignore them for now.

17
00:01:10,400 --> 00:01:15,680
And I'm going to create the repository using create a repository.

18
00:01:15,680 --> 00:01:17,120
So there we go.

19
00:01:17,120 --> 00:01:22,540
And this is telling me everything that I need to do to set up the new repository.

20
00:01:22,540 --> 00:01:28,059
So we don't do the if you've done this kind of thing before, we are going to focus on

21
00:01:28,059 --> 00:01:30,940
creating the repository on the command line.

22
00:01:30,940 --> 00:01:35,559
This is the corresponding Linux directory that you are going to need.

23
00:01:35,559 --> 00:01:38,620
So I'm going to create a directory new Git repo.

24
00:01:38,620 --> 00:01:42,260
And I need to make sure that all of these commands are done here.

25
00:01:42,260 --> 00:01:46,379
Before doing that, let's go to the slide so that we know a little bit better what is going

26
00:01:46,379 --> 00:01:48,820
on behind the Git repository.

27
00:01:48,820 --> 00:01:52,699
So while working with Git, you may have to set some global options.

28
00:01:52,699 --> 00:01:54,580
These are client options.

29
00:01:54,580 --> 00:01:58,779
And the global options are written to the .gitconfig file.

30
00:01:58,779 --> 00:02:03,699
You can use gitconfig-l to show a list of all the global options that are available.

31
00:02:03,699 --> 00:02:11,100
And you should set your user information using gitconfig-globaluser.name, followed by your name.

32
00:02:11,100 --> 00:02:17,660
As well as your email address, gitconfig-globaluser.email.

33
00:02:17,660 --> 00:02:21,580
To set options on a product-only basis, that's also possible.

34
00:02:21,580 --> 00:02:24,860
You would use gitconfig without a minus minus global.

35
00:02:24,860 --> 00:02:29,020
And then the configuration is stored in your local Git repository, which is convenient

36
00:02:29,020 --> 00:02:33,580
if one repository needs different credentials than another one.

37
00:02:33,580 --> 00:02:39,199
After configuring the global settings, you can move on and create your Git repositories.

38
00:02:39,199 --> 00:02:43,580
So it starts on the Git server where the upstream repository is created.

39
00:02:43,580 --> 00:02:44,940
That's what we just did.

40
00:02:44,940 --> 00:02:48,300
Next, a directory on the local workstation is created.

41
00:02:48,300 --> 00:02:50,860
And there you would use gitinit.

42
00:02:50,860 --> 00:02:54,779
Gitinit is a command that is used to initialize the Git metadata.

43
00:02:54,779 --> 00:03:02,539
And this Git metadata makes that all the information that Git needs is created in this directory.

44
00:03:02,539 --> 00:03:06,220
Then it is good practice to add a readme.md.

45
00:03:06,220 --> 00:03:11,660
In the information on the GitHub website, you see that it's the next step to create a readme.md.

46
00:03:11,660 --> 00:03:18,699
And the readme.md is normally an introduction to what you try to accomplish through this Git repository.

47
00:03:18,699 --> 00:03:21,339
So that's why it's called readme, right?

48
00:03:21,339 --> 00:03:25,979
Apart from the readme.md, at this point, you can add other files as well.

49
00:03:25,979 --> 00:03:29,660
And from there, the normal Git command flow can be applied,

50
00:03:29,660 --> 00:03:34,619
which means that you are going to use git add start to add all files to the staging area,

51
00:03:34,619 --> 00:03:38,539
git commit minus m to commit these files to the head.

52
00:03:38,539 --> 00:03:44,619
And then you can move on and push the files from the head to the remote repository using git push.

53
00:03:45,899 --> 00:03:48,460
There are different Git push methods available.

54
00:03:48,460 --> 00:03:55,179
And before you issue your first push, you can use git config minus minus global push.default simple.

55
00:03:56,059 --> 00:03:59,660
If required, it will set the push method to simple.

56
00:03:59,660 --> 00:04:02,059
Should be the case already, by the way.

57
00:04:02,619 --> 00:04:06,860
So here I'm going to demonstrate what we can do to create

58
00:04:06,860 --> 00:04:10,699
the Git repository counterpart on my local Linux machine.

59
00:04:11,500 --> 00:04:15,979
So I'm going to create my Git repository, mkdir new-git-repo.

60
00:04:17,739 --> 00:04:21,179
And then I go in there, new-git-repo.

61
00:04:22,619 --> 00:04:24,779
And I use git init.

62
00:04:27,019 --> 00:04:28,380
So what is this doing?

63
00:04:28,380 --> 00:04:31,820
Well, it's giving some hint using master as the name for the initial branch.

64
00:04:32,459 --> 00:04:38,220
And using master, that is nowadays deprecated terminology.

65
00:04:39,019 --> 00:04:43,820
So I'm going to change the branch using the name main.

66
00:04:43,820 --> 00:04:48,940
We can also see that it initializes the empty Git repository in the .git directory.

67
00:04:48,940 --> 00:04:52,220
So when I use ls on .git, we see what?

68
00:04:52,220 --> 00:04:54,140
We see the structure that it has created,

69
00:04:55,100 --> 00:04:58,859
including the head and including all the other metadata that is required.

70
00:04:59,820 --> 00:05:05,660
Now I'm going to use echo git demo repo.

71
00:05:06,540 --> 00:05:07,579
Please ignore.

72
00:05:09,019 --> 00:05:11,980
I like to be specific because under my Git accounts,

73
00:05:11,980 --> 00:05:15,100
I have many followers who see what I'm doing.

74
00:05:15,100 --> 00:05:19,739
And I don't want these people to pick up the new Git repository and think it is important.

75
00:05:19,739 --> 00:05:24,220
So in my case, this readme.md is really worth considering.

76
00:05:25,100 --> 00:05:28,220
Then I'm going to copy a couple of random files.

77
00:05:28,220 --> 00:05:30,700
Let's copy etch star to dot.

78
00:05:31,260 --> 00:05:33,820
So now I have four files, and that is good enough.

79
00:05:34,380 --> 00:05:36,779
So I'm using git add star.

80
00:05:37,739 --> 00:05:41,019
That's always the first phase after adding files.

81
00:05:41,019 --> 00:05:43,820
Then I'm using git commit minus m.

82
00:05:44,380 --> 00:05:48,220
And git commit minus m requires a value.

83
00:05:48,220 --> 00:05:53,179
So that is what it's complaining about, because minus m is for message.

84
00:05:53,179 --> 00:05:57,019
And I need a message uploading some demo files.

85
00:05:58,299 --> 00:06:01,820
These messages describe why you are doing your Git push

86
00:06:01,820 --> 00:06:05,579
so that your fellow developers can see what you had in mind.

87
00:06:06,619 --> 00:06:08,940
And, uh-oh, what do we see here?

88
00:06:08,940 --> 00:06:12,140
It is telling me committer superuser root add.

89
00:06:12,140 --> 00:06:13,100
That is wrong.

90
00:06:13,100 --> 00:06:14,459
And you know why that is wrong?

91
00:06:14,459 --> 00:06:16,140
Yeah, you know why that is wrong.

92
00:06:16,140 --> 00:06:19,579
I never set the identity when I started.

93
00:06:19,579 --> 00:06:24,859
And that's the part git config minus minus global user dot email and so on.

94
00:06:25,420 --> 00:06:31,179
So what I'm going to do, I'm going to edit my configuration file.

95
00:06:31,179 --> 00:06:39,420
So git config minus minus global minus minus edit is opening the configuration file.

96
00:06:39,420 --> 00:06:43,579
And there it is telling me, hey, please adapt and uncomment the following lines.

97
00:06:44,140 --> 00:06:45,420
So that is one name.

98
00:06:45,420 --> 00:06:51,100
And it's the user dot name and the user dot email if you want to do it from the command line.

99
00:06:51,980 --> 00:07:05,820
So if I use git config minus minus global user dot email mail at sandervanvugt dot nl.

100
00:07:05,820 --> 00:07:07,579
That is not a random email address.

101
00:07:07,579 --> 00:07:10,140
That is the email address that belongs to my Git account.

102
00:07:11,019 --> 00:07:13,500
And then I need to do the same for my username.

103
00:07:14,140 --> 00:07:23,579
So there we go, git config minus minus global user dot name sandervanvugt.

104
00:07:24,859 --> 00:07:29,500
Now, you only need to do this if you actually want to contribute to the Git repository.

105
00:07:29,500 --> 00:07:30,540
And that's the case here.

106
00:07:30,540 --> 00:07:34,700
If you only want to clone a Git repo, you don't have to make yourself known.

107
00:07:35,500 --> 00:07:37,579
So back to my Git commit.

108
00:07:38,859 --> 00:07:43,179
And there we can see on-branch mess, nothing to commit, working tree clean.

109
00:07:43,179 --> 00:07:44,299
Oh, yeah, that is right.

110
00:07:44,299 --> 00:07:46,299
I already did my Git commit.

111
00:07:46,299 --> 00:07:51,420
Because of the error message about the username, I totally ignored the message that we see here.

112
00:07:51,420 --> 00:07:54,059
Four files changed and 10 insurgents.

113
00:07:54,059 --> 00:07:55,260
And that's OK.

114
00:07:55,260 --> 00:07:57,260
So now I'm going to use Git status.

115
00:07:58,220 --> 00:08:01,899
And on Git status, it's telling me that there is nothing to commit,

116
00:08:01,899 --> 00:08:05,100
meaning that we don't have any files that haven't been committed yet.

117
00:08:05,660 --> 00:08:09,339
So I am going to set my Git branch.

118
00:08:09,339 --> 00:08:11,420
Git branch minus m main.

119
00:08:12,140 --> 00:08:15,579
This is the main branch, the main environment in the Git environment.

120
00:08:15,579 --> 00:08:17,260
You can work with multiple branches.

121
00:08:17,260 --> 00:08:18,779
We'll talk about that later.

122
00:08:18,779 --> 00:08:22,299
But here I want to set my main branch to the name main.

123
00:08:22,940 --> 00:08:25,899
And then I'm going to identify the remote counterpart.

124
00:08:25,899 --> 00:08:28,059
Because so far, there's no connection.

125
00:08:28,059 --> 00:08:30,380
So far, this is just a local directory.

126
00:08:30,380 --> 00:08:33,419
So I need Git remote add origin.

127
00:08:34,299 --> 00:08:40,700
HTTPS colon slash slash GitHub.com slash Sander van Vugt.

128
00:08:40,700 --> 00:08:42,940
This is where your Git username comes in.

129
00:08:42,940 --> 00:08:45,020
Slash new Git repo.

130
00:08:45,900 --> 00:08:50,700
Now in the local repository metadata, I have identified the remote.

131
00:08:50,700 --> 00:08:55,979
And now I should be able to use Git push minus U origin main.

132
00:08:56,299 --> 00:09:00,460
And uh-oh, apparently something didn't work out all right with the username.

133
00:09:00,460 --> 00:09:06,140
So I'm going to enter my username and I'm going to enter my password.

134
00:09:06,140 --> 00:09:07,820
Aha, I know what is going wrong.

135
00:09:08,539 --> 00:09:10,219
I have strong authentication.

136
00:09:10,219 --> 00:09:13,580
So let me see if I get through the strong authentication.

137
00:09:15,099 --> 00:09:17,020
And uh-oh, what do I get here?

138
00:09:17,020 --> 00:09:18,619
Invalid username or token.

139
00:09:18,619 --> 00:09:22,299
Password authentication is not supported for Git operations.

140
00:09:22,299 --> 00:09:23,419
Yeah, that is right.

141
00:09:23,900 --> 00:09:24,940
Yeah, that is right.

142
00:09:24,940 --> 00:09:27,099
I have secured my system too much.

143
00:09:27,099 --> 00:09:29,979
So I need to work with an authentication token.

144
00:09:30,619 --> 00:09:36,780
So because I can't authenticate with a password, I am going to generate an SSH key.

145
00:09:36,780 --> 00:09:42,219
Git supports SSH key authentication and that's a pretty clean method.

146
00:09:42,219 --> 00:09:57,659
So I'm using SSH key gem minus TED25519 minus C followed by mail at sandervanvugt.nl.

147
00:09:58,460 --> 00:10:02,059
We need my identity in the key.

148
00:10:02,700 --> 00:10:04,299
Small typo, let me fix it.

149
00:10:05,820 --> 00:10:06,940
So I'm pressing enter.

150
00:10:06,940 --> 00:10:08,940
I don't want to do passphrase.

151
00:10:08,940 --> 00:10:11,979
And now I have my SSH public private key pair.

152
00:10:11,979 --> 00:10:15,979
Next, I need to add the SSH key to the SSH agent.

153
00:10:15,979 --> 00:10:24,539
In order to do so, I'm using eval on dollar SSH agent minus S.

154
00:10:27,020 --> 00:10:37,179
And there I'm going to use SSH add dot SSH IDEDED25519.

155
00:10:37,179 --> 00:10:41,260
And that is adding the identity to my current SSH agent.

156
00:10:42,140 --> 00:10:44,619
Now I'm going to get my public key.

157
00:10:44,619 --> 00:10:53,179
I'm doing so using a cat on dollar dot SSH slash IDED etcetera dot pub.

158
00:10:54,219 --> 00:10:56,619
And this is what I need.

159
00:10:56,619 --> 00:10:58,380
And next, I'm going to GitHub.

160
00:10:58,380 --> 00:11:00,940
And on GitHub, I'm going to add this key.

161
00:11:01,820 --> 00:11:06,219
So on GitHub, I need to go to my settings, which are right here.

162
00:11:07,739 --> 00:11:08,940
So here are the settings.

163
00:11:09,739 --> 00:11:13,739
And now in the settings, I select the SSH and GPG keys.

164
00:11:14,539 --> 00:11:16,539
And then I'm clicking new SSH key.

165
00:11:18,219 --> 00:11:20,780
And there I'm going to set a title.

166
00:11:22,460 --> 00:11:27,020
Linux plus demo machine key.

167
00:11:27,020 --> 00:11:29,099
And then I'm going to paste the key.

168
00:11:30,059 --> 00:11:30,859
So up.

169
00:11:32,299 --> 00:11:35,020
And there we can see the key is pasted.

170
00:11:35,979 --> 00:11:38,380
So now I'm clicking add SSH key.

171
00:11:39,340 --> 00:11:40,859
And we should be OK.

172
00:11:42,940 --> 00:11:44,219
So the key is now saved.

173
00:11:44,219 --> 00:11:47,260
And that means that we can get back to the Linux machine.

174
00:11:48,700 --> 00:11:53,419
And now I need to set the remote again for this new authentication method.

175
00:11:53,419 --> 00:11:56,700
The old authentication method was HTTPS.

176
00:11:56,700 --> 00:12:01,739
And now I need to change the protocol using git remote set URL.

177
00:12:02,059 --> 00:12:15,099
Origin, git at github.com, colon, my username, slash, new git repo dot git.

178
00:12:17,739 --> 00:12:19,020
Let's fix a small typo.

179
00:12:21,580 --> 00:12:22,539
Set URL.

180
00:12:23,340 --> 00:12:24,460
And that will do it.

181
00:12:25,340 --> 00:12:29,900
And now if I repeat my last failing command, where is it?

182
00:12:30,299 --> 00:12:31,099
Where is it?

183
00:12:31,099 --> 00:12:32,539
That was a git push.

184
00:12:33,260 --> 00:12:38,539
Then git push is telling me that the authenticity of GitHub can't be established.

185
00:12:38,539 --> 00:12:40,859
And I'm going to use yes to accept.

186
00:12:41,739 --> 00:12:47,260
And there we can see that the Git synchronization is now completed.

187
00:12:47,979 --> 00:12:49,099
Is that really the case?

188
00:12:49,099 --> 00:12:52,859
Well, if that is really the case, we can now go to the GitHub website.

189
00:12:52,859 --> 00:12:56,299
And on GitHub, we should be able to see it.

190
00:12:56,299 --> 00:13:01,020
Now, do notice that where normally in Git you use HTTPS,

191
00:13:01,020 --> 00:13:03,580
because of this SSH key-based authentication,

192
00:13:04,299 --> 00:13:10,299
you need to use git at github.com instead of HTTPS, colon, slash, slash.

193
00:13:10,299 --> 00:13:14,219
So the URL changes a little bit because of the change of the protocol.

194
00:13:14,780 --> 00:13:16,299
But in the end, it still works.

195
00:13:16,299 --> 00:13:17,500
Let's do one final check.

196
00:13:18,140 --> 00:13:21,900
So I'm going back to my repos.

197
00:13:22,859 --> 00:13:25,419
And here I can see my repositories.

198
00:13:25,419 --> 00:13:29,020
And there is new Git repo, updated one minute ago.

199
00:13:29,020 --> 00:13:30,140
Well, that's a good sign.

200
00:13:31,580 --> 00:13:33,659
And when I click it, yay, look at that.

201
00:13:33,659 --> 00:13:37,179
I can see the files that I originally added on Linux.

202
00:13:37,179 --> 00:13:38,299
So it's working.

