Learn Github in 20 Minutes

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
every one today we're talking about github a super-important topic will cover things like cloning pushing pulling for King making pull requests there's a lot of stuff to talk about if you're not already familiar with the basics of get things like adding and committing then take a look at my previous video I put out a link to it it's called learn get in 15 minutes and then come back to this one and there are pretty thorough notes for this video you can find the link down there in the description as well lots of content here sort of step-by-step guide to what I'm covering all right so let's start with the basics here what is github what is it compared to get what's the relationship so they are separate entities you can use git completely on its own it's just a version control system it tracks the changes to our files or our projects over time but github is what allows us to share our git repositories with team members we can publish things online and we can collaborate on open source projects it's kind of like a social network or a platform for git repositories if you think of something like let's say Photoshop you can make these Photoshop projects and you might want to collaborate with somebody so you put it up on Dropbox and then they download it and they work on it they put it back up on Dropbox you download that it's kind of like that relationship although that's a bit limited because Dropbox doesn't really have any features that allow you to do much in the browser you just download something whereas github has actual functionality that pertains to get in the browser so that will make sense when we get there so that's the relationship here git is the main technology github is the platform to share it and collaborate using git so if you're brand new to github the first thing you'll need to do is register an account go to github.com register you'll have to confirm your email I'm pretty sure you'll also be prompted to choose a subscription or a plan if you're just starting out I would just go with the free stuff you really don't need the paid version of github unless you're a company or you're working on something you want to keep secret but you still want to use github now how do we actually use github there's a bunch of different workflows in different scenarios the first one we'll talk about is when you have some code or repository on your machine that has nothing to do with github and you want it to be on get up you want to push it up to github so you can share it with somebody or collaborate with somebody else there or just post it online so people can see it to do that will first make our local repo with git I have one already if I type git status I do have a repository here it's extremely simple it is a single text file called playlist txt and it has a couple of songs and different artists and if I look at git log there's a couple commits I made the file I added two songs and then like five songs and then I outfit as them by artist name it doesn't really matter but whether it's a single file or a twenty or a thousand file application it's the same process that we're going to go through so I have my changes committed and this is all just on my computer to get it up on github we need to go to github.com and tell github we want to make a new repository we select a name then we have to connect the two I need to tell my local repository here is this URL for github that I want to be able to push my code up to we set up something called a remote and then we finally push using that new remote so the first thing we'll do is go to github I'm signed in here you can click up top new repository you can also go new right there it'll take you to the same place we'll give the repository a name I'll call this one playlist I'll give it a simple description we can choose public or private in the past you could only do public on a free account I think nowadays on a free account you're just limited to the number of private repos but I'm going to keep it public so you can see this and I'm not going to bother initializing it with a readme file but if you do want to read my file it's very easy to get one made for you by github so I'm going to click create and takes a moment and I'll see a new page so this gives me a couple of options here if I don't have a repository yet on my machine it tells me ok initialize one add commit and then deal with github but we have an existing repository so these are the two commands we need and this first one is what I was talking about adding a remote so a remote is just it's kind of like a label for a URL it's a way of telling it here is this remote place an online place where I want to be able to push code up to or retrieve code from so we need this you definitely we can just copy this entire command git remote add and then this part what we have as origin is just a name or a label for the remote in my terminal right now I have a command get remote - V this will list the remotes that I have right now I don't have any I haven't set any up but if I paste this in I'm gonna name it origin that's this pretty standard conventional name if you have one remote you could name it something else you could call it my github or random place online it doesn't matter you just need to reference that name it's kind of like a variable for a URL so I'm going to hit enter now if I type git remote - V again I now have a remote this URL has a name of origin so the final step to actually get my code up here is right now it's completely empty I need to push my code so it's not enough just to set up a remote we have to tell git when to push code up when to get our changes from the local version up to the github version so that's what this command is right here get push - you of origin master and this origin just needs to match the name of your remote so if you're following along it will be origin but if you named yours github place then you need to do a git push github place and then this right here is the branch and all my changes are committed on the master branch on branch master so I'm going to go with that but if I wanted to push a different branch up you can do that as well so I'm gonna hit enter and if you do this it may ask you for your github username and email you can't hurt a password you can't just push willy-nilly to anybody's repository and overwrite their changes you need to have permission so it's gonna check based off of your credentials now if I come back here and i refresh the page my code is here you'll see now I have my playlist txt file and I can view the commits if I click on for commits here are my commits that I had locally all of them are up on github so I can see the very first one where I just made the blank playlist txt the second one I added two songs in and so on here I reordered things so you can see I get a diff so that is pushing up and if I made more chain on my local version I commit them I would run this command get push - you origin master - push those changes up to github we set up the remote one time and then you push whenever you want to sync your changes up to github but now what I want to show you is what happens when somebody else makes changes so if I set up my repository so that I can permit other collaborators which is very easy if I just go into settings right here and then I go to collaborators I can add somebody which I just did and I'm gonna have Cody change this repository he's going to make a change and push it up and we won't have that change on our machine so then we'll need to pull down okay a couple hours later there's a new commit if I go to commits there's now five and you can see Cody's commits add my favorite adds my favorite and thanks for that Cody he added his song down there and you can see I don't have it on my local copy it's only on github so to get it it's kind of the inverse of pushing to origin/master well instead pull from origin master origin is the name of that remote and then master is the branch branch master that is where the change was made so I'm gonna try that now git pull and it's always a good idea to just make sure you don't have uncommitted changes git pull origin master so origin is that URL master is the branch cool it tells us one file change there was two insertions one deletion I think he moved something around accidentally and now if we hop over to our editor I can see Cody's lovely change that he added to this file Thank You Cody on the topic of pushing and pulling let's take a look at working with different branches other than master so I'm gonna make a new branch in one line get checkout dash B and let's say I want to make a relaxing playlist a separate version I don't want to change master but this will be a something I want to try out so get checkout - be relaxing I'm now on that branch I'll make some changes to the file okay so I added some new songs in I'm going to now commit this to this branch relaxing I'll just do git add playlist get commit and relaxing songs okay so now when I run git push instead of doing git push - you origin/master the branch I now want to push is relaxing so master is the only one currently on github but I'm telling it here's a new branch I want to add so give it a moment then we'll hop over to github refresh the page and you can see there's a change your recently pushed branches relaxing here I can toggle between the different branches so I'm on master right now this is what we see if I switch over to relaxing it's only the relaxing songs so that's pushing a different branch other than master up still using origin as the destination the remote all right so that's pushing up changes to github making your own repository being in charge of basically everything you can add collaborators and get they'll have permission to push and override your changes or make updates like Cody did to our playlist but that's not the only way of using github here's an example repository it's called face swap it is some code I think it's all Python and it helps you make these face swaps these deep fakes if I wanted to get this code on my machine that is open-source it's on github I can clone it so here is a new command we can just copy this URL click that button or command C and then a very important thing to note is that you do not want to clone a repository into another repository right now I'm inside of my playlist repository so I'm going to back out and then I'll make a new directory I'll call this one deep fake and then CD into that so I'd get status again just to make sure okay now we can run git clone and then paste that URL and this will probably take a while I think it's a pretty large repository so it's going to go and fetch all of those pieces all of the files the information all of the commit history all the git history everything and put it in a folder on my machine and I'll have everything but I won't be able to push up changes that would be pretty crazy if somebody puts an open-source project on github and anybody could change it without permission that doesn't really work as you saw I had to give Cody access I had to give him collaborator permission to allow him to push code directly to the repository so we're going to talk about a really common workflow that involves something called pull requests but first let me just show you what we end up with if we CD into faceswap there's a ton of files if I type git log tons and tons of commits I mean I could be scrolling for a long long time looks like there's how many 914 commits so I have all of that here but remember I cannot push up so if I want to make changes I want to try and contribute to an open-source project what I need to do is make a pull request and the workflow for that is a little different what we do is we actually fork a repository there's a button right here this makes you your own copy on github so it takes the exact current state of this application or of this repo and makes you your own version and you have permission to do whatever you want to that version then you can make changes push them up to your version to your fork and then you can make a request to faceswap for example the devs you write a little explanation on github I'll show it to you in a moment and then they can reject it or accept it and merge it in alright so let's take a look at how this works I have a much simpler repository open this is actually a demo repo from github called spoon knife the point is that you're supposed to fork it it doesn't really have any meaningful content in here it's just a educational repository that we can use instead of trying to fork and make changes to that faceswap which was a massive project and we don't want to bother the developers with something useless we're going to fork this repository so I'm gonna click Fork right now and I'm going to fork it to my account it will take a moment and it's making a copy for us like I said exactly the same state just our version we can do whatever we want with this we can add a thousand files we can do anything and this is the basic workflow we fork we clone our fork so we don't clone the original we cloned the fork and notice how the URLs cult / spoon knife forks from github / spoon knife so now we're going to clone it and again we don't want to do it inside of an existing repo so we're going to run git clone and then paste that URL colt slash spoon knife or whatever your fork is and then we should have a spoon knife directory and we should now have a repository in a couple of files so I'm going to make a change or two very quickly okay here's what we have an index.html I've read me and style stuff CSS let's just go in and make everything purple well at least the background color purple for star so we'll go with purple fantastic choice of color I might say so myself we're going to commit that change so git add styles going to commit we'll go with make everything purple okay and then we need to push so just double check we have our remote which we automatically get when we clone a repository we cloned it from this URL so it sets that as the origin for us so now we run a git push - you origin master we're pushing the master branch up to our fork oh I must spelled it there get myself a little heart attack and then if I go back to my fork on github we should see that my change is here if I just go to commits make everything purple now shows up awesome so we still haven't actually changed the original in any way or we haven't attempted - we've just updated our fork so they're out of sync and it tells me this this branch is one commit ahead of the actual original spoon knife if I do want to propose these changes fingers crossed hopefully the generous developers will accept my suggestion of making everything purple I can click on pull request right here so I'll click that and notice the screen is going to change I'm now looking at github slash spoon knife not cult slash spoon knife and I can compare the changes and I don't know I think I messed up some of the spacing with my vs code editor when I saved it updated the spacing to be tabs or but you can see my changes here everything else is the same it looks like this was all removed and we added but this is really the only new line so background color set it to purple and I'm going to click create pull request then all I do is add in a comment explain what this commit is why I'm trying to contribute it you can read the guidelines which I highly recommend you do if you plan on actually contributing and then we would just click create pull request and then we just wait and hopefully it's accepted and if it is those changes will become part of the original repository if it's not then we still have our own changes we're just making a suggestion to keep things simple I just had us make changes to the master branch and make a pull request from our Forks master but what a lot of open source repos want you to do is make a topic branch so here's react this is the official react repository if we look at pull requests there's quite a few open pull requests there's over 8,000 closed requests let's take a look at one of them like this pull request that was made and you'll see that it was not made from this developer Chris Davies master branch it was from a topic branch called dev tools 1 6 9 2 4 looks like the mechanics are absolutely the same it's just a different pattern to follow on these larger projects topic branches can help make it cleaner and easier to understand to pull requests we can see that this particular pull request has 171 additions 21 deletions and that's pretty much it it's open it's waiting for some action to be taken and lastly let's take a look at the other side of this experience of actually accepting or rejecting a pull request so while I was recording this I had Ellie one of my friends and co-instructors I had to make a pull request to the playlist repository that we've been working with if I go to the poll request tab I see one new pol request here it is adding Ellie's favorite song it's a good one I'm sure it's some sort of troll here so we can take a look at his code if we go to commits let's see what he did say you will ok it's actually not a sarcastic one Thank You Ally say you whale by Fleetwood Mac has been added in in his version he forked it as you can see it's coming from his master branch of his Fork now if I want to accept I can click review changes and decide to comment if I want some more discussion and give feedback if I want to approve I can do it right here so that's what I'm going to do now and click Submit I probably should have added a message and then I'm going to click merge pull request confirm merge and now you can see Colt approve these changes I merge the commit let's go back and take a look at what we have on the master branch playlist ext we now have that Fleetwood Mac song but on my version I don't have that if I just do get log on my local version I have nothing with le so if I want to get that I need to pull that change down it's only on github I'm working on the relaxing branch so I'm gonna get checkout master once again I misspelled it and then I'm going to pull from origin so git pull origin master and there we go we have one file changed one insertion if I type git log we can now see adding my favorite song that's coming from le and here it is we now have Ellie's contribution he forked it he cloned it he made his change he pushed his change sirs fork he made a pull request I accepted it that was merged in that was on github so then I pulled it down to my local repository and now I have it so it's quite the process if you're lost turned a little confused definitely take a look at the notes again I'm going to stop here there's still more to talk about around collaboration we could do a whole video on best practices for pull requests but hopefully this gives you a good overview of github you can use it on your own to showcase your code and share code you can collaborate with people at your trust and give them write permissions and you can use pull requests to suggest changes to open-source repos like anything in programming get in github take practice you really need to get used to those patterns but eventually they'll be ingrained in your brain for those of you who have been following along with my chicken journey this is Stevie he is definitely a he is a rooster he's been waking me up every morning because right now he lives in the bedroom next to my room anyway thanks for watching I hope you enjoyed it and Stevie and I will see you next week
Info
Channel: Colt Steele
Views: 434,932
Rating: undefined out of 5
Keywords: git, github, #learntocode, #code, #webdev, #js
Id: nhNq2kIvi9s
Channel Id: undefined
Length: 20min 0sec (1200 seconds)
Published: Thu Oct 17 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.