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,740 In order to do something on GitHub, you need to have an account. 5 00:00:22,740 --> 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,660 with your current account. 7 00:00:34,660 --> 00:00:37,419 This is bringing me to my Git environment. 8 00:00:37,419 --> 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,700 And in that new Git repository, I need to give it a name and the name is new Git repo. 10 00:00:49,700 --> 00:00:53,380 And there I can see that new Git repo is available. 11 00:00:53,380 --> 00:00:55,380 So I can choose what I want to do. 12 00:00:55,380 --> 00:00:59,099 So choose visibility, set to public, and that is okay. 13 00:00:59,099 --> 00:01:01,099 You can set private as well. 14 00:01:01,099 --> 00:01:06,779 And if you set the Git repo to private, well, then it's not accessible by everybody. 15 00:01:06,779 --> 00:01:08,139 And there are more options. 16 00:01:08,139 --> 00:01:10,379 I will ignore them for now. 17 00:01:10,379 --> 00:01:15,660 And I'm going to create the repository using create a repository. 18 00:01:15,660 --> 00:01:17,099 So there we go. 19 00:01:17,099 --> 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:09,899 And you should set your user information using gitconfig-globaluser.name followed by your 32 00:02:09,899 --> 00:02:17,660 name, 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,979 --> 00:02:48,339 Next, a directory on the local workstation is created. 41 00:02:48,339 --> 00:02:50,899 And there you would use gitinit. 42 00:02:50,899 --> 00:02:54,860 Gitinit is a command that is used to initialize the Git metadata. 43 00:02:54,860 --> 00:03:02,580 And this Git metadata makes that all the information that Git needs is created in this directory. 44 00:03:02,580 --> 00:03:06,300 Then it is good practice to add a readme.md. 45 00:03:06,300 --> 00:03:11,699 In the information on the GitHub website, you see that this is the next step to create a readme.md. 46 00:03:11,699 --> 00:03:18,740 And the readme.md is normally an introduction to what you try to accomplish through this Git repository. 47 00:03:18,740 --> 00:03:21,419 So that's why it's called readme, right? 48 00:03:21,419 --> 00:03:26,059 Apart from the readme.md, at this point, you can add other files as well. 49 00:03:26,059 --> 00:03:29,740 And from there, the normal Git command flow can be applied, 50 00:03:29,740 --> 00:03:34,660 which means that you are going to use git add start to add all files to the staging area, 51 00:03:34,660 --> 00:03:38,580 git commit minus m to commit these files to the head. 52 00:03:38,580 --> 00:03:45,979 And then you can move on and push the files from the head to the remote repository using git push. 53 00:03:45,979 --> 00:03:48,619 There are different Git push methods available. 54 00:03:48,619 --> 00:03:55,860 And before you issue your first push, you can use git config minus minus global push dot default simple. 55 00:03:55,860 --> 00:03:59,779 If required, it will set the push method to simple. 56 00:03:59,779 --> 00:04:02,820 Should be the case already, by the way. 57 00:04:02,820 --> 00:04:10,860 So here I'm going to demonstrate what we can do to create the Git repository counterpart on my local Linux machine. 58 00:04:16,739 --> 00:04:22,940 So I'm going to create my Git repository, mkdir new-git-repo. 59 00:04:22,940 --> 00:04:27,820 And then I go in there, new-git-repo. 60 00:04:27,820 --> 00:04:32,220 And I use git init. 61 00:04:32,220 --> 00:04:33,579 So what is this doing? 62 00:04:33,579 --> 00:04:37,660 Well, it's giving some hint using master as the name for the initial branch. 63 00:04:37,660 --> 00:04:44,260 And using master, that is nowadays deprecated terminology. 64 00:04:44,260 --> 00:04:49,100 So I'm going to change the branch using the name main. 65 00:04:49,100 --> 00:04:54,179 We can also see that it initializes the empty Git repository in the .git directory. 66 00:04:54,179 --> 00:04:57,540 So when I use ls on .git, we see what? 67 00:04:57,540 --> 00:05:00,299 We see the structure that it has created, 68 00:05:00,299 --> 00:05:05,059 including the head and including all the other metadata that is required. 69 00:05:05,059 --> 00:05:11,779 Now I'm going to use echo git demo repo. 70 00:05:11,779 --> 00:05:14,299 Please ignore. 71 00:05:14,299 --> 00:05:20,299 I like to be specific because under my Git accounts, I have many followers who see what I'm doing. 72 00:05:20,299 --> 00:05:24,899 And I don't want these people to pick up the new Git repository and think it is important. 73 00:05:24,940 --> 00:05:30,299 So in my case, this readme.md is really worth considering. 74 00:05:30,299 --> 00:05:33,420 Then I'm going to copy a couple of random files. 75 00:05:33,420 --> 00:05:36,420 Let's copy etch star to dot. 76 00:05:36,420 --> 00:05:39,579 So now I have four files, and that is good enough. 77 00:05:39,579 --> 00:05:43,019 So I'm using git add star. 78 00:05:43,019 --> 00:05:46,220 That's always the first phase after adding files. 79 00:05:46,220 --> 00:05:49,579 Then I'm using git commit minus m. 80 00:05:49,579 --> 00:05:53,299 And git commit minus m requires a value. 81 00:05:53,299 --> 00:05:58,299 So this is what it's complaining about because minus m is for message. 82 00:05:58,299 --> 00:06:03,459 And I need a message uploading some demo files. 83 00:06:03,459 --> 00:06:06,980 These messages describe why you are doing your Git push 84 00:06:06,980 --> 00:06:11,700 so that your fellow developers can see what you had in mind. 85 00:06:11,700 --> 00:06:14,100 And, uh-oh, what do we see here? 86 00:06:14,100 --> 00:06:17,299 It is telling me committer, superuser, root, add. 87 00:06:17,299 --> 00:06:18,339 That is wrong. 88 00:06:18,339 --> 00:06:19,619 And you know why that is wrong? 89 00:06:19,619 --> 00:06:21,260 Yeah, you know why that is wrong. 90 00:06:21,260 --> 00:06:24,820 I never set the identity when I started. 91 00:06:24,820 --> 00:06:30,459 And that's the part git config minus minus global user dot email and so on. 92 00:06:30,459 --> 00:06:36,420 So what I'm going to do, I'm going to edit my configuration file. 93 00:06:36,420 --> 00:06:42,179 So git config minus minus global minus minus edit 94 00:06:42,179 --> 00:06:44,619 is opening the configuration file. 95 00:06:44,619 --> 00:06:49,299 And there it is telling me, hey, please adapt and uncomment the following lines. 96 00:06:49,299 --> 00:06:50,579 So that is one name. 97 00:06:50,579 --> 00:06:54,540 And it's the user dot name and the user dot email 98 00:06:54,540 --> 00:06:57,179 if you want to do it from the command line. 99 00:06:57,179 --> 00:07:08,220 So if I use git config minus minus global user dot email 100 00:07:08,220 --> 00:07:11,100 mail at sandervanwugt.nl. 101 00:07:11,100 --> 00:07:12,820 That is not a random email address. 102 00:07:12,820 --> 00:07:16,220 That is the email address that belongs to my Git account. 103 00:07:16,220 --> 00:07:19,339 And then I need to do the same for my username. 104 00:07:19,339 --> 00:07:20,420 So there we go. 105 00:07:20,420 --> 00:07:30,100 Git config minus minus global user dot name sandervanwugt. 106 00:07:30,100 --> 00:07:32,339 Now, you only need to do this if you actually 107 00:07:32,339 --> 00:07:34,700 want to contribute to the Git repository. 108 00:07:34,700 --> 00:07:35,820 And that's the case here. 109 00:07:35,820 --> 00:07:40,660 If you only want to clone a Git repo, you don't have to make yourself known. 110 00:07:40,660 --> 00:07:44,059 So back to my Git commit. 111 00:07:44,059 --> 00:07:47,420 And there we can see on branch master, nothing to commit. 112 00:07:47,420 --> 00:07:48,459 Working tree clean. 113 00:07:48,459 --> 00:07:49,540 Oh, yeah, that is right. 114 00:07:49,540 --> 00:07:51,500 I already did my Git commit. 115 00:07:51,500 --> 00:07:53,779 Because of the error message about the username, 116 00:07:53,779 --> 00:07:56,500 I totally ignored the message that we see here. 117 00:07:56,500 --> 00:07:59,260 Four files changed and 10 insurgents. 118 00:07:59,260 --> 00:08:00,420 And that's OK. 119 00:08:00,420 --> 00:08:03,380 So now I'm going to use Git status. 120 00:08:03,380 --> 00:08:07,100 And on Git status, it's telling me that there is nothing to commit, 121 00:08:07,100 --> 00:08:10,820 meaning that we don't have any files that haven't been committed yet. 122 00:08:10,820 --> 00:08:14,540 So I am going to set my Git branch. 123 00:08:14,540 --> 00:08:17,459 Git branch minus m main. 124 00:08:17,459 --> 00:08:20,899 This is the main branch, the main environment in the Git environment. 125 00:08:20,899 --> 00:08:22,500 You can work with multiple branches. 126 00:08:22,500 --> 00:08:24,059 We'll talk about that later. 127 00:08:24,059 --> 00:08:28,179 But here, I want to set my main branch to the name main. 128 00:08:28,179 --> 00:08:31,100 And then I'm going to identify the remote counterpart. 129 00:08:31,100 --> 00:08:33,299 Because so far, there's no connection. 130 00:08:33,299 --> 00:08:35,659 So far, this is just a local directory. 131 00:08:35,700 --> 00:08:39,500 So I need git remote add origin. 132 00:08:39,500 --> 00:08:46,020 HTTPS colon slash slash github.com slash Sander van Vugt. 133 00:08:46,020 --> 00:08:48,140 This is where your Git username comes in. 134 00:08:48,140 --> 00:08:51,140 Slash new Git repo. 135 00:08:51,140 --> 00:08:55,979 Now in the local repository metadata, I have identified the remote. 136 00:08:55,979 --> 00:09:03,659 And now I should be able to use git push minus U origin main. 137 00:09:03,659 --> 00:09:07,619 And uh-oh, apparently something didn't work out all right with the username. 138 00:09:07,619 --> 00:09:10,299 So I'm going to enter my username. 139 00:09:10,299 --> 00:09:13,260 And I'm going to enter my password. 140 00:09:13,260 --> 00:09:15,260 Aha, I know what is going wrong. 141 00:09:15,260 --> 00:09:17,099 I have strong authentication. 142 00:09:17,099 --> 00:09:21,940 So let me see if I get through the strong authentication. 143 00:09:21,940 --> 00:09:23,700 And uh-oh, what do I get here? 144 00:09:23,700 --> 00:09:25,380 Invalid username or token. 145 00:09:25,380 --> 00:09:29,179 Password authentication is not supported for Git operations. 146 00:09:29,179 --> 00:09:30,140 Yeah, that is right. 147 00:09:30,140 --> 00:09:32,340 I have secured my system too much. 148 00:09:32,340 --> 00:09:35,900 So I need to work with an authentication token. 149 00:09:35,900 --> 00:09:39,260 So because I can't authenticate with a password, 150 00:09:39,260 --> 00:09:41,979 I am going to generate an SSH key. 151 00:09:41,979 --> 00:09:45,500 Git supports SSH key authentication. 152 00:09:45,500 --> 00:09:47,460 And that's a pretty clean method. 153 00:09:47,460 --> 00:09:57,380 So I'm using SSH key gem minus TED25519 minus C 154 00:09:57,419 --> 00:10:03,739 followed by mail at sandervanvugt.nl. 155 00:10:03,739 --> 00:10:07,900 We need my identity in the key. 156 00:10:07,900 --> 00:10:11,059 Small typo, let me fix that. 157 00:10:11,059 --> 00:10:12,219 So I'm pressing enter. 158 00:10:12,219 --> 00:10:14,179 I don't want to do passphrase. 159 00:10:14,179 --> 00:10:17,179 And now I have my SSH public private key pair. 160 00:10:17,179 --> 00:10:21,219 Next, I need to add the SSH key to the SSH agent. 161 00:10:21,219 --> 00:10:32,179 In order to do so, I'm using eval on $SSHagent minus S. 162 00:10:32,179 --> 00:10:42,380 And there I'm going to use SSH add .SSHIDED25519. 163 00:10:42,380 --> 00:10:47,419 And that is adding the identity to my current SSH agent. 164 00:10:47,419 --> 00:10:49,940 Now I'm going to get my public key. 165 00:10:49,940 --> 00:10:59,419 I'm doing so using cat on $.SSHIDED et cetera .pub. 166 00:10:59,419 --> 00:11:01,940 And this is what I need. 167 00:11:01,940 --> 00:11:03,619 And next, I'm going to GitHub. 168 00:11:03,619 --> 00:11:07,059 And on GitHub, I'm going to add this key. 169 00:11:07,059 --> 00:11:13,099 So on GitHub, I need to go to my settings, which are right here. 170 00:11:13,099 --> 00:11:14,979 So here are the settings. 171 00:11:14,979 --> 00:11:19,820 And now in the settings, I select the SSH and GPG keys. 172 00:11:19,820 --> 00:11:23,419 And then I'm clicking New SSH Key. 173 00:11:23,419 --> 00:11:31,460 And there I'm going to set a title, Linux Plus Demo Machine 174 00:11:31,460 --> 00:11:32,299 Key. 175 00:11:32,299 --> 00:11:35,299 And then I'm going to paste the key. 176 00:11:35,299 --> 00:11:37,460 So up. 177 00:11:37,460 --> 00:11:41,140 And there we can see the key is pasted. 178 00:11:41,140 --> 00:11:44,539 So now I'm clicking Add SSH Key. 179 00:11:44,539 --> 00:11:48,179 And we should be OK. 180 00:11:48,179 --> 00:11:49,460 So the key is now saved. 181 00:11:49,460 --> 00:11:53,900 And it means that we can get back to the Linux machine. 182 00:11:53,900 --> 00:11:56,140 And now I need to set the remote again 183 00:11:56,140 --> 00:11:58,619 for this new authentication method. 184 00:11:58,619 --> 00:12:01,940 The old authentication method was HTTPS. 185 00:12:01,940 --> 00:12:03,979 And now I need to change the protocol using 186 00:12:03,979 --> 00:12:15,059 git remote set URL, origin, git add github.com, colon, 187 00:12:15,059 --> 00:12:24,460 my username, slash, new git repo dot git. 188 00:12:24,460 --> 00:12:29,780 Let's fix a small typo, set URL. 189 00:12:29,780 --> 00:12:31,979 And that will do it. 190 00:12:31,979 --> 00:12:36,419 And now if I repeat my last failing command, where is it? 191 00:12:36,419 --> 00:12:38,460 That was a git push. 192 00:12:38,460 --> 00:12:42,179 Then git push is telling me that the authenticity of GitHub 193 00:12:42,179 --> 00:12:43,739 can't be established. 194 00:12:43,739 --> 00:12:46,859 And I'm going to use Yes to accept. 195 00:12:46,859 --> 00:12:51,219 And there we can see that the git synchronization 196 00:12:51,219 --> 00:12:53,260 has now completed. 197 00:12:53,260 --> 00:12:54,460 Is that really the case? 198 00:12:54,460 --> 00:12:55,820 Well, if that is really the case, 199 00:12:55,820 --> 00:12:58,059 we can now go to the GitHub website. 200 00:12:58,059 --> 00:13:01,539 And on GitHub, we should be able to see it. 201 00:13:01,580 --> 00:13:04,820 Now, do notice that where normally in git 202 00:13:04,820 --> 00:13:09,500 you use HTTPS, because of this SSH key-based authentication, 203 00:13:09,500 --> 00:13:13,299 you need to use git add github.com instead of 204 00:13:13,299 --> 00:13:15,539 HTTPS, colon, slash, slash. 205 00:13:15,539 --> 00:13:18,179 So the URL changes a little bit because 206 00:13:18,179 --> 00:13:20,020 of the change of the protocol. 207 00:13:20,020 --> 00:13:21,619 But in the end, it still works. 208 00:13:21,619 --> 00:13:23,299 Let's do one final check. 209 00:13:23,299 --> 00:13:28,340 So I'm going back to my repos. 210 00:13:28,340 --> 00:13:30,619 And here I can see my repositories. 211 00:13:30,619 --> 00:13:34,340 And there is new git repo, updated one minute ago. 212 00:13:34,340 --> 00:13:36,900 Well, that's a good sign. 213 00:13:36,900 --> 00:13:38,940 And when I click it, yay, look at that. 214 00:13:38,940 --> 00:13:42,419 I can see the files that I originally added on Linux. 215 00:13:42,419 --> 00:13:44,539 So it's working.