How to Use Git & GitHub Desktop Tutorial for Beginners

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
you know get isn't hard to learn and GitHub desktop makes it even easier to learn hi I'm Cameron McKenzie I'm the editor-in-chief at the serverside.com and I want to show you how to use GitHub desktop to do all of the key things that you would do with a git repository like pushing and pulling using branches doing isolated development merging and just managing your commit history like doing things like rebases commits resets reverts maybe even some cherry picking now to start off I've actually got a blank Windows operating system here with nothing installed on it and I've just gone to desktop.github.com and click to download and I'm just going to install GitHub desktop right from the start just to show you that I'm not pulling any tricks on my local operating system now one thing I will tell you is that I do have my own GitHub repository set up so I created one let me see if I can find it here there it is I believe that the name of my account is learn GitHub desktop fast which is a fairly apt name for my repository and you can see that when I try to install GitHub desktop the one thing it asks me to do is to well sign into GitHub just so that it can connect to my GitHub account and maybe work with some repositories that I have in there so I click OK looks like it's found my account I'm going to authorize the application through the browser asked me to open GitHub desktop but hey GitHub desktop is already open looks like it wants to just configure things just set things up locally I'm going to say yes use my GitHub account and name and boom all of a sudden we are ready to go working with GitHub desktop now if you've worked with Git before maybe if you haven't uh you might know that well when you work with Git you use something called a repo uh repo was the place where you store all of your code where your history of code is where all of your branches are so starting off the first thing that we need to do is create a git repository and it's not a GitHub repository GitHub is the vendor that has the cloud-based git service but git is the underlying tool that makes all of this git stuff happen so right off the bat I'm going to click this option to create a new repository on your hard drive what's the name I'll call it my first repo not a very creative name you can give it a description I'm going to initialize this with a readme I like to have just one file in the root of my repo right when I create it and adding a readme file will do that not required and then well if you're working with Java C octothorpe or python there's certain files that you probably don't want to check into the repository you can click a git ignore file I'm going to ignore the git ignore for now and maybe I'll choose an MIT license who knows maybe I want to share this with people and have other people share this example so boom all of a sudden my first repo has been created but it's pretty boring because there's nothing in it right I mean I brought in the readme file I've got I guess the license file that I asked to be created but there's no good files of my own so I need to add some files and how do do you add files to this well I'm actually just going to go and open this repository in Windows Explorer so this is one of the options you go repository show in Explorer and it'll end up showing you the folder on your hard drive where this git repository was created so you can see it looks like under documents GitHub my first repo there's the readme file there's the license what I want to do is I want to create a brand new file of my own and I'm just going to right click say create a new text document I'm going to call it Alpha Dot txt nothing crazy right just keep it simple as we're starting out and you can see I haven't done anything through git I've just created a new file on my file system the whole point of git is to keep track of the files that you create the files that you update the files that you edit the files that you delete and also maintain a history of those changes every time you do a commit in Git it kind of takes a stamp of where you are and keeps a history of that I always compare it to like a save point in a video game right you get so far in a video game and you hit a certain point and it it kind of saves the fact that you got there and then you can move on you play a little longer then you get to another save point that's what commits are like in git those are your video game save points that you know if you start work and you mess around you get killed a little bit you can always go back to them revert back to them reset back to them might even be the better terminology okay so I've got that created on my file system let's come over here to GitHub desktop and look at that it says that Alpha dot txt has been created see it's keeping track of what's going on on my file system so you know right down here it says do you want to commit this file and I'll say um first commit I guess I can put a description in there but I want to move quickly through this so I'm going to click commit and boom all of a sudden we've got a commit to our git repository even click on this tab here it says the history and you can see well we have the initial commit that that's the one where we created the repo and we added the license and the readme now we've got our first commit on here that's Alpha dot txt you know what I might do I might go down and see if I can create another file I'm actually just gonna adjust my screen here so we can see everything at the same time so there's alpha.txt do you know what I'm going to do next you guessed it beta dot txt so now we've got a second file in here and much if I moseyed on over here to changes look at that GitHub desktop is recognized that well I've got another change to my local file system and it says to me hey do you want to commit this change you want to make a save point so that I don't know maybe one time in the future you can come back here if you you like what's happening and hey I'm all for that and I'll type in second commit why not click commit to main look at this we're cooking with gas here we've got three commits the initial commit our first commit with Alpha our second commit with beta geez what should we do next now I know what you're thinking you're thinking we're going to create charlie.txt but we're not you see when you're working with GitHub desktop well the idea is that you'll be creating files locally when you work with Git everything actually happens locally um you know you create your files locally you do your commits locally then at some point in the future where you're real happy with what you've done you you push it up to GitHub and so right now if I actually looked at my GitHub account you see there's my GitHub account right here there's learn GitHub desktop fast I'm going to do a Refresh on this page and look it's telling me that I don't have any repositories right your repositories hey I don't have any repositories well you saw me create a repository I can see on the left hand side of my screen a repository called my first repo I can see three commits in it but that's all local that's all of my local file system that's not been pushed up to GitHub so maybe that's the next thing we need to do take this local repository we created and push it up to GitHub now sometimes you'll start with a GitHub repo and pull it down that's called cloning other times you might start locally and then push your stuff up that's what we did we initialized a local git repo added some files added some commits and then pushed it up to and then pushed it up to GitHub well we haven't pushed it up to GitHub yet so why don't we do that so right now I've got the option over here took me a while to find it under repository I've got the uh under repository I've got the option here to push and what a push is is that's taking the repository in your local file system and all of the commits that have happened and pushing it up to GitHub so here I go I'm going to click publish Repository it's going to do the SSH handshake maybe authenticate me make sure everything worked properly and then I'm going to come over here to GitHub and boom all of a sudden my first repo is now up on GitHub so we're creating git repos locally we're adding files we're adding commits then it's just a matter of repository push now we've got all of this floating up in the cloud on our GitHub server you can even come into my first repo and take a look and see we've got Alpha and beta there now did we talk about Charlie a little while ago let's create Charlie but let's create Charlie up on GitHub so you've got this option here create a file I'm going to create a new file I'm going to call it Charlie Dot txt you might as well put something in there then I'm going to click commit changes and I'll call this the third commit just to keep things consistent and boom now all of a sudden I've got charlie.html in my file system up on GitHub took a refresh to see it but there you see Alpha Beta Charlie but that's up on GitHub if I come back to my file system over here haha where's Charlie oh Charlie's on the server Charlie's on GitHub Charlie hasn't been pulled down to my local file system so that's what I'm gonna do next I'm going to come over here I'm going to say Repository pull and keep your eye on the right hand side there boom charlie.txt is now on my local file system so what have we done we've initialized a git repository we've added commits we've pushed to GitHub we've added files in GitHub we've pulled those files down boy is there anything else to do in git what else is there um well a couple of things um I'm going to add another file here so I'm going to go and create a file and create a new file and I'll call it devo.html devo.txt and look at that I didn't spell it right so let me just correct that correct that whip there we go devo.txt click let's see oh yeah it recognizes those changes let me do this I'll do a fourth commit committed to Maine look at my history and now watch this one of the things I can do here is I can say you know what um I'm not really happy with that second commit what I want to do is I want to actually well I want to revert that commit and watch this I'm going to say revert changes in commit and look at the files on the file system over there just keep your eye on the prize and boom there we go we can see that that beta.html file has been removed so there you go that's the revert that's the idea of being able to mess around a little bit with your commit history right that's one of the things that you can do with Git You can mess around with your commit history you can push and do things collaboratively and we can branch which is something we'll get into in just a minute but okay Alpha Charlie Devo what are we missing here I guess we're missing Echo so let me just do this I'm going to add an echo dot txt to the repository if I come over here and take a look at GitHub it knows once again what is this I'm losing track is this the fifth commit I'll do a fifth commit here and you know here's another thing that you can do um you can actually go into your history of commits take a look at any of these commits here and um you might want to amend the previous commit sometimes you mess up with your ad or you mess up the comment that you make on a commit so right now I'm actually going to say hey let's amend this commit and uh go into the history right click say amend commit and then oh no no I'll change it to fifth commit looks good I guess just something like that so there we go we've now amended The Fifth Fifth commit and if we go look at our get commit history you can now see that it says fifth commit looks good we have now gone in and amended the commit so boy oh boy I mean how much more can we do here we have done pushing we've done pulling we've created repositories we've done a get revert we've done the commit you know I'm just going to push this back up to the server once again I mean when you're working with get GitHub and GitHub desktop doing that collaborative pushing and pulling is always really important we can see if I do a refresh over here I've got Alpha Beta Charlie on the server but what do I have on my local repository I've got Alpha Charlie Devo and Echo so it's time to go repository and push up to that remote GitHub repository I'll come back over here take a look at that repo do a little bit of a refresh of that repo what do you say about a man with more than one watch a man with one watch always knows what time it is but a man with two watches is never quite sure I got a couple of different browsers open here so I don't know which one to go to I hit the wrong one a second ago anyways Alpha Beta Charlie is what was previously on the server I'm going to click on refresh and boom now we have Alpha Charlie Devo and Echo beta is gone because we did that revert on the client side and now the the server is consistent with what I've got at my local file system so there you go that is I mean those are some of the key things that you do when you start working with Git GitHub desktop and GitHub in the cloud now when you're working with Git and you're working with GitHub you know really git can do three things git allows you to maintain a commit history that's the the whole save point idea right the idea of being able to go back in time when something messes up it allows you to do collaborative work so collaborative work is doing stuff locally doing your commits locally but when you've got something you're happy with and you want to share you can push that up to the the server and share it with other members of your team because maybe they've got GitHub desktop installed as well and they're pulling from this repository as well every time somebody on the team makes a commit and does a push the other big thing that you can do with Git is isolated development in branches Okay so what I want to do right now is I want to create a new Branch okay so I'm going to go over here and send it Branch let's create a brand new branch what do we call it and I'll we'll call it um my new Branch why not it's not a real creative name but gets the job done so I've now created a new Branch the idea of a branch is that it's an a place where you can do isolated work you can write code you can take chances if you mess something up well nobody else necessarily knows about that Branch especially if it's local so you can just delete it nobody knows that there was a problem you can share it so other people can jump in maybe help you out if you have a problem and when you've done something that you really like you can merge that Branch into the main branch or Master Branch or development Branch push and then share your code with everybody else maybe make it part of a continuous integration or continuous development and continuous deployment cycle so right now I'm on a new Branch current branch is my new Branch the other Branch was main you can see that right there we used to call the the the key Branch Master we don't just call it faster anymore we call it main um and uh I guess let's continue this phonetic alphabet let's add in well it's F I think f is foxtrot Okay so we've got Fox Trotta now speaking of the foxtrot that's a dance and I think you've done this dance before right there's their foxtrot there's our sixth commit is that the sixth commit I think so um so we've got another commit here uh let's add another one what is it now let's say four and play some golf there we go golf dot txt is the next one and uh is this our seventh commit this is a lot of commitment here who said I was afraid of a commitment that's just silliness okay so now we've got this Branch here it's our new Branch it's separate from that good old main branch and we've got a couple of commits on it we've got Golf and we've got uh foxtrot watch this so notice we've got Fox Trot and golf over here I'm going to switch branches I'm going to go back to the main branch watch this when I go back to the main branch Golf and foxtrot disappear they're not there anymore those two files are only part of that other Branch my new Branch right and if nobody sees that Branch if you've never pushed that Branch everything in that branch has its own separate commit history watch I mean I can do these magic tricks all day I'm like David Copperfield here look I switched the back to my new branch and then there we go foxtrot and golf have been created there now here's the other cool thing I'm going to go back to the main branch here and what am I going to do I'm going to create another Branch I'll create another branch called my other branch I'll create that branch and over here in my other Branch what will we do um well we'll have a new file called G-Force Dot txt and then another new text document called honor dot txt by the way notice that I added two files here I've been doing one file all the time when you're working with Git like you do a bunch of work like you should commit often but you know you'll be doing like you know five or six changes you know working on a method a file or this or that you know and then you know every few hours you might do a commit you don't do a commit after every file but here we've been doing that just to show you how to do commits and push code and do reverts and all of those other things here I've created two files you can see GeForce and honor and uh what is this the eighth commit something like that okay we'll put that in there and you can see that this commit has G-Force and honor in it but it doesn't have a foxtrot and golf if I go to my new branch you can see foxtrot and golf there and if you go to the main branch you don't see any of those new ones right they're uh not there so um it's all kind of interesting stuff so what do you do well here's the idea you do work in isolated branches you take chances you maybe mess things up um you revert problems you revert commits maybe even do a reset and then when you're happy with what you've done you merge that code that is in that Branch back into the main branch and then it's all merged together so let's do that right here I've got Alpha Charlie Devo and Echo then let's actually merge and so we're going to select the option to merge into the current Branch what do we want to merge into the current Branch we want to merge the files in my new Branch so I'm going to say let's create a merge commit here keep your eye on the prize over there on the file system and when the merge happens boom foxtrot and golf come in now we can also merge that other branch in so merge into the branch what it looks like I spelled Branch wrong there don't tell anybody about that okay and boom now we've actually merged that other branch in there and you know at that point in time you know we probably don't even need those branches so um let me just take a look at those branches can we actually go in and delete those branches Branch delete my new branch branch there's main there's my other branch Branch can we delete that branch there we go delete again okay and now when we go look at our branches we've only got the main branch all the code has been brought in there so there you go that's how you actually create branches do isolated development and then merge the code back in once you're you're done working on all of that stuff so that's all pretty cool now I'm actually going to push this back up so let's go take a look we want to become experts at doing pushes and pulls so right here we've only got Devo and Echo let's do a push up to the repository there do a little refresh and boom we've got all the files here um we've got up to honor there um what else is next I'm going to actually create a new file and I'll call it Ian Dot txt and say commit changes and what is this the ninth commit something like that okay and again I've got files now up on the server do a little refresh we should be able to see e in there there's Ian dot txt again that is not on the file system so if I look at the file system it's not here now I'm going to do something a little different I'm going to do a fetch if I say repository fetch what that actually does is that actually brings down changes from the server but it doesn't integrate them into my file system until I explicitly ask for those changes to be merged in so watch this I'm going to do a fetch says fetching from origin refreshing but you can see here oh you know we did a fetch but it didn't bring it in then we click and say okay now pull that fetch in and after we then merge that fetched branch that will then come into our file system so the fetch brings the files down but it doesn't work merge it into your workspace you then have to do a subsequent merge to actually get that in so that's the idea of the fetch there now um I'm going to do another Branch here and I'm going to call it the last branch that I'm going to create here okay so we've got that last Branch here and I don't know what are we up to J so I'll create a a new text document called Hal uh Pinot dot txt there we go that's our J boy you're probably getting bored of this now right you're experts um is this the 10th commit there we go commit to the last Branch now we have this on the last Branch again look the jalapeno is there but that jalapeno is not on the main branch here right so if I switch to Main no jalapeno if I switch to the last branch the jalapeno is there now what we did before was we just merged that in but I'm going to do something a little differently watch this I'm going to say create a pulled request and what a pull request is is it it actually takes the changes on your branch sends them to the server and then maybe asks one of the administrators of the the repository to take a look at the changes in your branch and then merge them into master or main or development or whatever the important branch is that all the developers are merging their good code into so I'm going to create a pull request and the idea is I am requesting that somebody who manages the GitHub server pulls my code into their repository into the repository they're managing into the the GitHub repository really so say create a pull request so it's like you're gonna have to publish this Branch to create it so I'm like okay I'm good with that publish that Branch create this pull request notice I'm now up here on GitHub and it says do you want to create a pull request for this 10th commit and I'll say yeah that's uh that's why I did that that was the whole point to create a pull request and so now that pull request goes to the server and then the next time somebody logs in they'll see that there's a pull request there now I mean I'm the only one that's running this repository but you get the idea that you might do a pull request as a junior Dev and then the team lead might log in the next day say oh you know Cameron did a pull request I'm going to take a look at that code and see if I can pull it in so I'm going to take a look at this 10th commit here oh look at that that 10th commit is amazing and then I don't know the team lead can then say merge pull request they then merge everything is successful then we can actually go back to the repo and go in take a look at well the last branch is there and there's the jalapeno Dot txt file but we can actually look at the main branch and there's the jalapeno.txt file in there as well and that has been merged in not by us just doing a push and say hey take my changes and shove them into mate but I've actually got a pull request I've said hey I like this code I'd like somebody's senior somebody with authority over the repository to take a look at the code and if it meets all the checks if it meets the quality criteria maybe you could then merge it into the the main code base and then kick off a continuous integration or continuous delivery Pipeline with GitHub actions but we're not going to talk about GitHub actions today so there you go that is a big overview a big look at GitHub desktop and honestly I think we've covered most of the the features that are available here I've got a couple of other tutorials over on the server side and those tutorials will cover things like doing a rebase and a squash of some of your commits we I think other things we could do is maybe configure a git ignore file that's a cool thing that you can do um but I mean really we've covered practically everything that you can do with GitHub desktop in the last half an hour or so there's really not much more to it and if you can Master these things you've mastered git right because what does git do git just allows you to maintain a commit history right that those video games save points where you can go back in time and change things and and take a look at what happened and who did what in the repo it allows you to do collaborative Computing that's the push and pull and maybe even the fetch commands that we we saw as we were working on the repository and sharing our code locally and pushing it to GitHub where other members of the team who are part of that GitHub organization could work with that code as well and then finally the other thing that git allows you to do is isolated development in branches and that's what we were doing that's why we created the my first Branch my other Branch the new brand what branch there's a branch there that I misspelled um you create branches you take chances you develop code you do edit and then when you're happy with what you've got you take your code and then you merge it into the main branch or the master Branch or the development Branch if you're using git flow or something like that and then that's it right collaborative work isolated development and managing your local commit history that is what git and for that matter GitHub is all about and I think we did a whirlwind tour of all of the the major options there so I don't know I think that's uh pretty cool if you understand that you understand get pretty good now I've got a lot of other tutorials over on the server side I'm the editor-in-chief of the serverside.com we've got lots of tutorials on devops git GitHub scrum agile Jenkins you name it we've got a bunch of tutorials over there um if you're ever interested in my personal Antics I'm posting more and more on Twitter all the time so at cameronmcnz is my handle um and a couple of other things you know uh there's a couple of books in the back there um I wrote a book about hibernate and jpa um so if you're doing Java development you should check that out I also wrote another book called it was called Pickering a Springfield so it's all about the fact that uh the hometown of The Simpsons is actually based on a small town in Ontario Canada called Pickering so that's a good little book to take a look at and I've also been working with a freelancer over on the server side who's writing some great stuff about scrum and agile she's just published a book called The scrum Master certification guide and if anybody wants to learn about scrum or even get scrum certified go over to Amazon and check that book out it's uh well worth the read um so there you go and with us I guess uh finally I mean you're probably watching this on YouTube right so like why don't you subscribe on YouTube
Info
Channel: Cameron McKenzie
Views: 32,550
Rating: undefined out of 5
Keywords: cameronmcnz, theserverside, java, jakarta, jakartaee, git, github, gitlab, dvcs, versioncontrol, tortoisegit, gitgui, atlassian, bitbucket, linux, azure, devops, devopstools, gitops, gitopstools, azuredevops, softwaredeveloper, softwareengineer, softwarearchitect, javascript, css, tailwing
Id: MaqVvXv6zrU
Channel Id: undefined
Length: 34min 4sec (2044 seconds)
Published: Thu Aug 24 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.