In this video, you'll learn more about creating Git repositories.
In order to show you the video, I need to start at a public Git environment.
So I'm going to use GitHub to do so.
In order to do something on GitHub, you need to have an account.
So you sign up if you don't have an account yet, or you sign in if you want to sign in
with your current account.
This is bringing me to my Git environment.
So I am going to use new to create a new Git repository.
And in that new Git repository, I need to give it a name and the name is new Git repo.
And there I can see that new Git repo is available.
So I can choose what I want to do.
So choose visibility, set to public, and that is okay.
You can set private as well.
And if you set the Git repo to private, well, then it's not accessible by everybody.
And there are more options.
I will ignore them for now.
And I'm going to create the repository using create a repository.
So there we go.
And this is telling me everything that I need to do to set up the new repository.
So we don't do the if you've done this kind of thing before, we are going to focus on
creating the repository on the command line.
This is the corresponding Linux directory that you are going to need.
So I'm going to create a directory new Git repo.
And I need to make sure that all of these commands are done here.
Before doing that, let's go to the slide so that we know a little bit better what is going
on behind the Git repository.
So while working with Git, you may have to set some global options.
These are client options.
And the global options are written to the .gitconfig file.
You can use gitconfig-l to show a list of all the global options that are available.
And you should set your user information using gitconfig-globaluser.name, followed by your name.
As well as your email address, gitconfig-globaluser.email.
To set options on a product-only basis, that's also possible.
You would use gitconfig without a minus minus global.
And then the configuration is stored in your local Git repository, which is convenient
if one repository needs different credentials than another one.
After configuring the global settings, you can move on and create your Git repositories.
So it starts on the Git server where the upstream repository is created.
That's what we just did.
Next, a directory on the local workstation is created.
And there you would use gitinit.
Gitinit is a command that is used to initialize the Git metadata.
And this Git metadata makes that all the information that Git needs is created in this directory.
Then it is good practice to add a readme.md.
In the information on the GitHub website, you see that it's the next step to create a readme.md.
And the readme.md is normally an introduction to what you try to accomplish through this Git repository.
So that's why it's called readme, right?
Apart from the readme.md, at this point, you can add other files as well.
And from there, the normal Git command flow can be applied,
which means that you are going to use git add start to add all files to the staging area,
git commit minus m to commit these files to the head.
And then you can move on and push the files from the head to the remote repository using git push.
There are different Git push methods available.
And before you issue your first push, you can use git config minus minus global push.default simple.
If required, it will set the push method to simple.
Should be the case already, by the way.
So here I'm going to demonstrate what we can do to create
the Git repository counterpart on my local Linux machine.
So I'm going to create my Git repository, mkdir new-git-repo.
And then I go in there, new-git-repo.
And I use git init.
So what is this doing?
Well, it's giving some hint using master as the name for the initial branch.
And using master, that is nowadays deprecated terminology.
So I'm going to change the branch using the name main.
We can also see that it initializes the empty Git repository in the .git directory.
So when I use ls on .git, we see what?
We see the structure that it has created,
including the head and including all the other metadata that is required.
Now I'm going to use echo git demo repo.
Please ignore.
I like to be specific because under my Git accounts,
I have many followers who see what I'm doing.
And I don't want these people to pick up the new Git repository and think it is important.
So in my case, this readme.md is really worth considering.
Then I'm going to copy a couple of random files.
Let's copy etch star to dot.
So now I have four files, and that is good enough.
So I'm using git add star.
That's always the first phase after adding files.
Then I'm using git commit minus m.
And git commit minus m requires a value.
So that is what it's complaining about, because minus m is for message.
And I need a message uploading some demo files.
These messages describe why you are doing your Git push
so that your fellow developers can see what you had in mind.
And, uh-oh, what do we see here?
It is telling me committer superuser root add.
That is wrong.
And you know why that is wrong?
Yeah, you know why that is wrong.
I never set the identity when I started.
And that's the part git config minus minus global user dot email and so on.
So what I'm going to do, I'm going to edit my configuration file.
So git config minus minus global minus minus edit is opening the configuration file.
And there it is telling me, hey, please adapt and uncomment the following lines.
So that is one name.
And it's the user dot name and the user dot email if you want to do it from the command line.
So if I use git config minus minus global user dot email mail at sandervanvugt dot nl.
That is not a random email address.
That is the email address that belongs to my Git account.
And then I need to do the same for my username.
So there we go, git config minus minus global user dot name sandervanvugt.
Now, you only need to do this if you actually want to contribute to the Git repository.
And that's the case here.
If you only want to clone a Git repo, you don't have to make yourself known.
So back to my Git commit.
And there we can see on-branch mess, nothing to commit, working tree clean.
Oh, yeah, that is right.
I already did my Git commit.
Because of the error message about the username, I totally ignored the message that we see here.
Four files changed and 10 insurgents.
And that's OK.
So now I'm going to use Git status.
And on Git status, it's telling me that there is nothing to commit,
meaning that we don't have any files that haven't been committed yet.
So I am going to set my Git branch.
Git branch minus m main.
This is the main branch, the main environment in the Git environment.
You can work with multiple branches.
We'll talk about that later.
But here I want to set my main branch to the name main.
And then I'm going to identify the remote counterpart.
Because so far, there's no connection.
So far, this is just a local directory.
So I need Git remote add origin.
HTTPS colon slash slash GitHub.com slash Sander van Vugt.
This is where your Git username comes in.
Slash new Git repo.
Now in the local repository metadata, I have identified the remote.
And now I should be able to use Git push minus U origin main.
And uh-oh, apparently something didn't work out all right with the username.
So I'm going to enter my username and I'm going to enter my password.
Aha, I know what is going wrong.
I have strong authentication.
So let me see if I get through the strong authentication.
And uh-oh, what do I get here?
Invalid username or token.
Password authentication is not supported for Git operations.
Yeah, that is right.
I have secured my system too much.
So I need to work with an authentication token.
So because I can't authenticate with a password, I am going to generate an SSH key.
Git supports SSH key authentication and that's a pretty clean method.
So I'm using SSH key gem minus TED25519 minus C followed by mail at sandervanvugt.nl.
We need my identity in the key.
Small typo, let me fix it.
So I'm pressing enter.
I don't want to do passphrase.
And now I have my SSH public private key pair.
Next, I need to add the SSH key to the SSH agent.
In order to do so, I'm using eval on dollar SSH agent minus S.
And there I'm going to use SSH add dot SSH IDEDED25519.
And that is adding the identity to my current SSH agent.
Now I'm going to get my public key.
I'm doing so using a cat on dollar dot SSH slash IDED etcetera dot pub.
And this is what I need.
And next, I'm going to GitHub.
And on GitHub, I'm going to add this key.
So on GitHub, I need to go to my settings, which are right here.
So here are the settings.
And now in the settings, I select the SSH and GPG keys.
And then I'm clicking new SSH key.
And there I'm going to set a title.
Linux plus demo machine key.
And then I'm going to paste the key.
So up.
And there we can see the key is pasted.
So now I'm clicking add SSH key.
And we should be OK.
So the key is now saved.
And that means that we can get back to the Linux machine.
And now I need to set the remote again for this new authentication method.
The old authentication method was HTTPS.
And now I need to change the protocol using git remote set URL.
Origin, git at github.com, colon, my username, slash, new git repo dot git.
Let's fix a small typo.
Set URL.
And that will do it.
And now if I repeat my last failing command, where is it?
Where is it?
That was a git push.
Then git push is telling me that the authenticity of GitHub can't be established.
And I'm going to use yes to accept.
And there we can see that the Git synchronization is now completed.
Is that really the case?
Well, if that is really the case, we can now go to the GitHub website.
And on GitHub, we should be able to see it.
Now, do notice that where normally in Git you use HTTPS,
because of this SSH key-based authentication,
you need to use git at github.com instead of HTTPS, colon, slash, slash.
So the URL changes a little bit because of the change of the protocol.
But in the end, it still works.
Let's do one final check.
So I'm going back to my repos.
And here I can see my repositories.
And there is new Git repo, updated one minute ago.
Well, that's a good sign.
And when I click it, yay, look at that.
I can see the files that I originally added on Linux.
So it's working.