Git and Version Control System Tutorial | You SHOULD use these

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey what's going on welcome back to nerd academy i'm your host james and in this video we're going to learn about git and version control and why you should be using it in your project so let's get into it so version control is software that runs locally on your system that can provide tracking and control over changes to your source code so as you make changes to your source code file the version control can track all these changes and if you've never used version control you may have actually tried to use this like in school where you're making your uh all your edits and you're saving the files as new files like final edit final draft and final final dot doc you know what i'm talking about so version control kind of just provides that capability without having to manually save all your changes locally in different folders and different files because that just becomes a mess and one of the most popular version control software systems is git you can use online hosts such as github or git lab or bitbucket or even your own server that is running git all these are basically providing clouds for your git repos because using these online services are quite helpful if you're working on a team and they actually provide backups in case your system fails so you can be working on code locally and then push it to the server while another team member is working on another piece of code and then they push that to the server too this allows for a team to work on the same source code in a parallel manner i do prefer git lab over github but both are quite powerful and provide many extra services like continuing integration and other features but gitlab has like a kanban board which i have not seen in github this is where i can create and track like little stories or little stickies if you will where i can track the progress and move them around and actually create branches from there are free ones out there such as trello or you can even just use your own stickies that you write at home and put them up on your board and move the stickies around like you would in a scrum meeting all right let's go install git locally and get you set up using github and start learning how to use git you can go to git dash scm.com and download git most linux distributions that i've seen have git in their repo so you can use their package manager to download it install it with mac it requires homebrew so you're just gonna run brew install git windows has an installer you can download and when you run that it will set it all up for you all of these should have everything set up for you and you should be ready to use git once it's all installed you can verify that you have it installed by running get version in your command line before we get started head over to github.com and create yourself an account it's pretty simple and straightforward and it walks you through the process once you've got an account set up let's go ahead and make a repo now that your account is created you're probably landing on something page like this is probably a little empty and it might not have anything like i got a few repos here if you want to create a new repo there's a little button here with a book green button that says new so what we need to do is create the name of the repo so this will be available at in my case it'll be github.com slash nerd academy dev slash whatever this repo name is so i'm going to call this git and you can put a description in here if you want you can make it public or private and you can add a readme or get ignore and if you have a license if you're doing some open source stuff at the bottom we just hit create repository then you'll come to a page that looks like this this helps you especially if you've never done this before kind of figure out what you need to do so the quick and dirty if you've done it before this is the first one that says yeah it has this information here this may look kind of weird to you this is called an ssh i have a key set up so all i would have to do but if you're just starting you probably don't have an ssh key set up in your github account we can save that for another day so what you want to do is just copy this you can probably press this button here should copy it to your clipboard then you go over to your terminal and you're gonna type git clone and that's a url we just copied and then hit enter and it should clone it locally now it says warning you appear to have cloned an empty repository that's because there's nothing in it so we can go into that repo and there's nothing in there actually actually if you're on a unix system you press ls-a we got something called a.get we can go peek in there real quick quick this is going to have all the information that will help track all the changes that you make to your uh source code on your uh machine here locally let's go back up and let's let's go ahead and make a readme markdown file so quick brief uh one hashtag is kind of like an h1 header in markdown so we could just say this is the get learning repo write that out if your work if you're when you're in a repo if you ever want to know what's going on inside your repo as far as like if you have some changes you need to check in and all that stuff it's get status so it tells me the branch i'm on i have no commits and it tells me i have an untracked file readme.md and it tells you what you can do you can get add in the file git add will add changes so the version control system can track those changes otherwise it doesn't know we have to manually add those so there's a couple ways you can do that it's either git add and the file itself so we'll add that or if you have a bunch of changes and you want to add everything it's git add dot so it'll add everything from the local from your current directory and below or you can do git add dash dash all so if you actually have removed files it will actually track those changes too so for our case here we'll just do get add readme and if you hit tab it should auto complete and knowing which files that are on track that you're about to add so then you hit enter it says the branch i'm on and i have no commits yet but changes to be committed is this readme file so what we can do next is actually commit those changes that we've added so we're going to do git commit and then you can add a message dash m so if you wanted to add a commit message i'll show you in the browser when we after we push these changes up there's a initial commit so so this could be anything you want it to be it it should just be kind of some general information about what you've changed in your source code so we just hit get status again it tells us uh where what the branch we're on we have nothing to commit the working tree is clean but it should be saying that we're one commit ahead so let's see what happens if we do get push so it's going to ask for a username that you set up your account with that's going to ask for your password so yours should work out but i have set up an ssh key so it doesn't even want me to be able to push this way so okay since i had an ssh key set up i could not push with my username and password but it should work for you i just went ahead and recloned my repo using ssh instead so now that you've pushed it to the server if you just refresh the page there you go so in about all the cloud hosts if you have a dot readme file i mean a readme.md file it will show up kind of on the home page of the repo so it's a read me about the repo so people coming and browsing your code know what's about so now let's take this one step further and do something called creating a branch branches are great for features that you want to test out they are separate from your main branch so when you create a branch and use it nothing you do will affect the main branch once you're done kind of testing out the new feature and getting it all the work you can merge it back to the main branch or you can just get rid of it if it doesn't really work out that feature is not what you wanted so let's go test that out so on your main page of your repo you click this little down thing here for the main branch and you can type in what you want the branch to be i'll just call it feature and then you click this little create branch feature from master and it tells you right here this branch is even with like the main branch so i've made no changes on this branch so right now it looks exactly the same so if we wanted to merge this branch in there would be no issues so to get this branch locally we need to go back to our terminal and pull it in we do get pull it says hey there's a new branch here and to check out that branch we do get checkout we're going to call we're going to say feature so it tells you it's set up to track remote branch feature from origin and it's switched to that branch so anything we do right now inside this repo we push it up will not go to the main branch it'll stay on this feature branch so let's say we wanted to add a go file of course package main port format funk main and we'll just say hello world all right such an exciting feature but we really wanted to test this out first so let's test it out and see if it works so it works all right let's go ahead and do what we did before so we can check our status the status says your branch is up to date with origin features so that is on the server we have an untracked file main.go so we can add i'll use the dot this time so that added everything in that current directory so it added main.go and then we can do what we did before is commit and we'll add a message added shiny new feature hello world now we've committed our change now we'll push it so for you it probably asks for a username and password now we go back to github and we can go ahead and refresh this page here and we can see this main.go file is on our feature branch but if we go over to the main branch oh we got a 404 because that file does not exist so so all this the main branch has all it has is this readme file if we go to the feature we added now it has this main dot go so it's quite useful if someone if you're making something and it's not going to break the main branch because usually you're going to have some branch that is going to be the one that is like the source code and what you're going to use continuous integration and continuous development so that's the branch that you're going to you're going to build from and then deliver to a client or server for your website or whatever you're doing so this is very handy if you have a branch that you branch off and you mess with and it's not affecting the main branch and then when everything's working you can merge it back in and that's usually with something called a pull request so as you can see this little big read button here it says compare and pull request so if we hit that button so we open up a pull request that other people on your team will be notified hey we got some code that we want to merge back into our main branch here i don't really have a comment because i already have it over here add a shiny new feature of hello world and then we just create a pull request so on github it automatically goes to this little page here after you create the pull request and since there's no one else on the team i can just go ahead and merge the pull request so what this is gonna do we made our branch we messed with it and the main branch hasn't been updated yet and now we're gonna merge it back in so it's gonna take all the code and go right back so the main branch will now have this main.go file and confirm the merge and pull request successfully merge and close so if we want we can delete the branch or we can keep it there sometimes it's useful to delete it it depends on your project so we'll just leave it for now go back to the code and on the main branch now we have this main.go file if we go back to our local system we go get pull again and we'll just go ahead and get check out our main branch here and it's asking us go ahead and get pull so all changes are there now from our merge so there you go all right well that wasn't too bad was it that was your kind of your first foray into version control and git and github it's very powerful and it can do a lot and i even learn stuff using it from time to time because there's a lot you can do with it it's a quite amazing tool and it's very powerful for software to build so if you want to learn more about software development just watch this video right here and we'll see you in the next one [Music] [Music] you
Info
Channel: NerdCademy
Views: 62
Rating: undefined out of 5
Keywords: git, git basics, git tutorial, git tutorial for beginners, github, github branches, github merge, github pull request, github tutorial, github tutorial for beginners, programming, programming tutorial, should I use version control, should use github, software developer, software development, software development process, software development tutorial, version control basics, version control system, version control tutorial, version control with git, version control with github
Id: tyRu8CtVWK4
Channel Id: undefined
Length: 11min 44sec (704 seconds)
Published: Tue Oct 19 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.