Now, this is not an entire section dedicated to how to use git. I'm only going to show you a few basic commands because I have an entire course dedicated to git. This is simply going to show you how to configure it and get it working on your system.
and I'm going to create a project's directory here so I can type mkdir which stands for make directory, projects then I'm going to cd which stands for change directory into the projects and then let's just create another directory and this is going to be at test one. So I'll say mkdir and we'll say hello-git just like this and we'll change into our hello-git directory.
Now, what git allows us to do is to create code repositories that are on our local machine and then can also be shared on a public site like this. And if you go through the course then you're going to become familiar with exactly how to work with it.
But before we can do that we actually need to get git installed on our systems. I'm gonna give us some more room here and usually the way that you would do this is by typing git init and it says what we would expect. We don't have git on the system yet. So it gives us all error message.
I did this on purpose so that you could see that Linux is very helpful with allowing you to install dependencies and other kinds of programs on your system. So right here if I type out what it says because it says "The program git is currently not installed you can install it by typing sudo apt install git". So that's what I'm going to do.
So sudo apt install git it's going to ask for my system password so I'll type that out and what it's going to do is going to go out and pull down the git software and install it on the system for us.
So this is a very helpful way of being able to install all kinds of different code libraries and applications and so you're going to be typing app git quite a bit as you work with Linux and this is also going to help you as you progress on your development journey. Because if you work with diploid applications and you deploy them on your own servers usually those are going to be Linux based servers and so all of the commands that were typing right now are going to be the same exact commands that you're going to type and that you're going to go through when you configure your own systems.
So now that we have git installed let's try that same command. I'm going to try git init once again and now if I hit enter now it worked and it says initialized empty git repository in this location.
so I'm going to simply type out a single file and so I can type vim and actually this will be another good lesson. Because we do not have vim installed yet. So if I type vim README.md and make sure that you type out exactly like this.
This should give us the same error. Yes, it says a program vim can be found in the following packages and so now we can do the same thing. Type sudo apt install. Just a word just get type the regular vim
and it's going to go install vim and if you've never heard of vim it is a text editor that you can use inside of the terminal and it's not necessary to learn vim even though I absolutely love it and I use it on a daily basis. It's not necessary that you need it for any of these courses but if you are interested I do have a course on vim as well. I'll explain the commands to type out right now if you've never used them before.
Now if you're following along and this is just coming completely out of left field for you do not worry. Like I said this is not a course on git this is simply showing you how to install it on your system. Later on, you'll learn exactly how to use git and version control and all of those kinds of things. But for right now as I'm going through these steps each one of these is ensuring that git is working on your system. So if you're not understanding what's going on right now don't worry just follow along and as long as it's working and you're not getting any errors that means that you're setting up your system right. And later on, you'll get to the point where you understand this.
So now that I've typed this out and it's showing me that we have untracked files which is that ReadMe file. That means that I simply need to add this to my commit so that means I'm going to add it to the project and let git know about it. So I can say gt add and then a dot. And now if I type git status it is going to now be green and it's because we added it into our git repository and now it's ready for us to commit.
So now it says Tell me who you are. So this is a good thing if you have never installed git on your system and because I'm working with a completely fresh install it wants to know exactly who we are. So the way that we can do that is by typing git config --global and then user.email and then type in whatever your email is so I'm just gonna say jor...@devcamp.com and then ask us to do the same thing for our name and for this one I'm just gonna get rid of where it said email I'll say name and them do the same thing here with my full name. Hit enter and that's done.
And so now if I go and I type the same message so this git commit -m "Initial comment". And also if you're curious how I'm getting back to these commands if you just hit the up and down arrows that allows you to access your history of everything you've typed inside of the terminal.
And so hopefully you can see as I'm going through each one of these steps it's perfectly fine when you run into errors. I've been doing this for well over 15 years I run into errors every single day throughout the day. You're going to be running into errors constantly. And part of the reason why keep the errors on here is because there's a good chance that the error that I run into you also will run into and if you can watch me work through them and see the logic behind the error and also how to fix it. Hopefully, they'll help you understand how to configure your systems and work through bugs yourself.
So now that we have that we are ready to connect our system with github. So we have everything in this project this hello git project. And now we're ready to push this up to our profile. So if you are loaded in your account you can click on plus click on new repository
and I'm just going to say hello-git now. This is the same name that I gave this in the terminal in our local machine but it doesn't have to be. You could call this a thing that you want it to be but I usually like to keep the naming similar and the reason for that is because there have been many times where I will have an old repository here in github that I find that I want to work on again and if I have the naming different it's going to be very hard to find on my local machine. So that's a reason why I usually like to have the name the same but it doesn't matter for the sake of it actually working.
So I want this to be public. If it's private then you're going to have to pay for a private repo. I do not want to initialize it with a readme notice that this is the file that we already created. So I'm going to click Create repository
and as you may or may not notice if you are very detail oriented. I have actually come back and I've redone this part of the video. I originally built out the rest of the guide using HTTPS and then I decided I wanted to change it up and show you ssh is the more secure protocol it does require more steps. But I figured that it would be better to do that. It will take us a little while longer but from now on you are going to be able to use this on all of your projects with your virtual machine.
The first thing that we need to do before we can set this up is we need to tell github about our machine. And so the way we're going to do that is we're going to create a public key so that whenever we push from our machine here to github it's automatically going to know us. And so this is going to be a much more secure way of doing it.
If you do not want to follow along then as soon as we perform this next step which is to create our public key and set it inside of github then you can just follow along using HTTPS. One of the other reasons why I wanted to do this is because if you ever want to use two-factor authentication then you're going to have to use the SSH. And so I didn't want to shortchange you and I felt bad after I finished the guide because I felt like it would be better to give you the full and most secure way of doing it. So I am back here and we're going to do it.
Now I'm going to blackout part of the screen here because I can't show you all of my SSH keys and everything like that because I have done work for a number of organizations that require security and that I have confidentiality agreements. So I click on this blackout part of the screen and then I'm going to show you obviously the elements that you need so if you right click right here it's going to give you instructions on how to generate an SSH key. So open this up in a new tab
But if this is a new virtual machine that you're going to use then you shouldn't have anything on it. So if you paste this in and we're going to paste with control+ shift + V. Not just control + V. And if you hit enter you can see that we don't actually have any full public keys so we can run it again in a little bit. If you have a public key it's going to look something like this where it has the extension of pub at the very end of it.
so I'm going to copy this code all the way up to where it says your_...@example.com. Copy that and let's paste it in and then I'm going to type my email. You type your email into it and then hit return. It's going to generate it and it asks what file to save the key to.
just hit enter because we don't need to give anything besides the default. It's going to ask for a key phrase I'm not going to type any key phrase in. Just hit enter, the same passphrase again, hit enter again and it has generated the key for us.
it knows that we're on a Linux machine and so this shows you how to copy this on your clipboard. So there are a few ways you could do this but they give you some nice instructions and so in case you're following along and you have it on mute or anything then I'm going to just use these so I'm going to paste this in.
64591212e2