1.6: Cloning Repo and Push/Pull - Git and GitHub for Poets

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
- Hello I am continuing my tutorial series called Git and GitHub for poets and I'm very excited about this particular section because what I'm going to do in this session is crucial to your life as a user of Git and GitHub. What I did before was show you all of these concepts, right? Here's my list of concepts, you have a Git repository you can make commits which are like changes, you can make branches, you can merge branches, you can fork, you can do a pull request all these types of things that you can do with the Git software. You can do all those things just using the GitHub website through its interface however the truth of the matter is if you're going to be working with this for open source projects or even other kind of creative ideas of how you might want to work with Git you're ultimately going to want to work on your own laptop. So in the previous video I talked through the basics of just using this terminal so if you don't know how to use terminal go back and watch the previous video but if you do you're in the right place and you're ready to actually download and install Git onto your local computer. Now I'm not going to do this in the video so if you're watching this in real time pause go to this URL git-scm.com, download, install Git. Once you've done that open up terminal and you'll be ready to continue with me. So to make sure everything's working what you want to do and I'm going to, whoops (laughs) I just want to get into the right place so I'm in the trash? (laughs) Okay I want to be just in, I want to be on my desktop. Okay, so I am now on my desktop that's where I want to be. Be somewhere, your documents folder, your desktop, where you can start adding files. Desktop's going to work for me and the thing that I want to do is just type the words Git. So if you see this you're in good shape. Now my fonts kind of big so this looks kind of like a mess, it'll hopefully look nice and neat on your particular laptop. I'm going to hit clear if you see this, now well I misspelled Git to make sure I got this error. If you see Git colon command not found then your Git is not installed properly try again, ask a question in the comments here. Hopefully I can help you figure out where you missed that or make another video for one of the common problems but hopefully you're actually, Git is working and when you only type Git what you get is a lot of explanation of well, you need to issue also a command, so everything about using Git locally is all about saying Git something like you can imagine what this is, Git commit, make a commit, make a change, make it, save a change. So the first thing though, like if I just type this, the first thing that's going to happen is saying, not a Git repository so this directory is not a Git repository. What is a Git repository? Remember this thing, this rainbow poem? This is a Git repository. So what you need to issue Git commands is a folder on your computer which is a Git repository. This is essentially a folder on the GitHub server, you now want a folder on your computer. So I could just go and grab this exact repository and bring it down to my computer and then work with it there and I'm going to do that in either this video or the next one but I think it would be useful just to show you what happens again when you start fresh. So there are two ways of starting fresh. One way is actually just saying Git init and I'm going to show that to you at the end of this video or in the next one but I think an easier way for you to work when you're getting started is make your repository on GitHub and then download it to your computer and I keep saying the word download but in a moment, soon I got to start saying push and pull because ultimately pull it or clone it is actually a new term so we're going to get some new concepts here and this idea of cloning. So cloning is the act of taking a repository that's on a server like GitHub and cloning it to your computer, downloading a kind of copy of it to your computer that you can work with and then you could push it back or you could pull from the server again if there are changes that are on the server that aren't in your computer, we'll get to that in a moment. Okay so here I am, so let's go back to GitHub and I'm going to to go over here and I'm going to say, create a new repository and I'm going to call this one Rainbow Song. This one will be a song and a song about rainbows, and one thing that I want to do that's kind of important here is I want to check this box here. Initialize this repository with a read me. The reason why I want to do this is it's going to make a lot easier to work with if the repository on GitHub has a file associated with it already. And I'll show you the difference when I show you get init a little bit later. Okay so I'm going to select that and I'm going to hit create repository and now something really. So this is an empty repository I did this before, it's my rainbow song but right here this is what's really really important. There is a special URL here, this is the URL for the repos file for its, for its repository. This is the URL you need to clone it to your computer. Now there are different options, choose a clone URL. HTTPS recommended so this is what you want to use if you don't want to get fancy. There is, in other words, when I'm going to do it this way and it's going to ask me for passwords every once in a while if I'm trying to save changes and that sort of thing, there is a way to store your user and password name permanently to be able to, on your laptop to be able to push and pull and work with GitHub that requires this other SSH option which I will show you in a separate video because it's kind of like this convoluted thing. So for now I just want to use this HTTPS and I want to hit copy and I want to go here, back to terminal and we're going to do our first local terminal Git command. Here it comes everybody. I need my drum roll sound effect. Git clone, by the way pasting works in terminal so I'm going to hit command V and you can see there it is and you can see that's the URL, GitHub.com/RainbowCoder/Rainbow-Song.Git. Incidentally this is exactly this same exact URL just with .Git at the end because .Git is actually kind of like this sync, saying I want the URL of the repository itself not the sort of web interface to the repository. And so once I'd hit that and I wish my font, I wish it fit all in one line. Let's see if I, there we go that's a little nicer. Once I hit enter you can see it's cloning out. For a large, if this was a repository with a lot of files this would take quite a while as it's downloading everything but you can see it counted objects three, total three. Reuse blah blah blah blah 100% done. Checking connectivity, done. So it's giving you some debug information about what's going on and now I can say open dot and I'm on to the desktop and we can see look, there's a repository called Rainbow Song. Now there's nothing in it but that read me file because that was the only thing that was in the repository in the repository on GitHub. So let's say I want to actually make some changes to it now. So what I'm going to do is I'm going to drag this down here and I'm going to open it with, I'm just going to open it with Sublime Text I was using, whoops. So any text editor will do. You can use Atom, actually there's some nice things about using Atom with Git, I mean I'll use that in a different video and I can just go to this file. You can see there's the that read me file. Now this read me file is written in a format called markdown and this markdown is just a markup language to like, and the pound sign means a header that sort of thing. So I just do a testing, a song about rainbows in the key of C major. So I'm going to make that change I hit save and now I'm going to show you another Git command so we're making a list of them, clone is one, here's another one that's very useful, Git status, okay? So I'm coming back over here and I'm going to show you Git status, Git status, ah not a Git repository, why is it not a Git repository? I cloned it, the directory is there but I'm not in that directory so I need to CD into that directory and I can make sure I've been there by saying I'm in desktop rainbow song and now I should be able hit Git status. Look at this, it's telling me lots of information. I'm on the branch master, remember branches I'm up to date with origin but I've modified this file so if I've modified this file now, even though, so this is what's different, when you were on GitHub and you edited a file and hit save you actually made, you changed the file and committed it to the repository at the same time. Right now this file is just floating there, is it changed? I could get rid of the change, I could just, I could keep it whatever but what I want to do is actually say that change I made I really want to commit it. So what I'm going to do is say, is Git commit. That's another command in this list. Now, oh commit is already up here so that's not a new command but we want to issue now this command commit and I want to issue that command locally. Now, commands need arguments. The first way I'm going to show you how to do this is with the argument dash a. The argument dash a essentially stands for all. Just like anything that was changed, anywhere, commit all of it. In probably in a separate video I'm going to show you about how you can only commit certain changes and not other changes and there's an add command which is like a step before commit but this is a good way of getting started Git commit dash a and I'm going to now, oh and then if I want to add a comment I'm going to dash M for a message, dash M for message I'm going to say, adding the key of C and in quotes so this is now, Git commish, commit. Git commish? Git commit dash a, commit any changes I made to any files dash M, with this message, adding the key of C. So I'm going to hit enter and you can see, ah now here's the thing, oh boy. So this is that it's going to happen to you once and only once in your life unless you change your name or email that sort of thing so it might happen to you again. What it's telling me is, it's saying I don't know who you are (laughs). Like I need an author to be associated with this particular Git change. Now, if I were on GitHub in the browser and I made a change it knows who I am because I'm logged in, right? I'm logged in as the user RainbowCoder so it doesn't have to ask me who I am but on my computer it doesn't know who I am. So what I need to do is tell my computer who I am who I'm going to be when I make Git changes. Now if you want to have multiple Git users that can get very like messy and complicated there's probably way of doing that. Maybe I'll make a video about that someday but for now I'm just going to do this, I'm going to actually just copy this command, Git config dash dat so to set my username RainbowCoder, that's my username, then I'm going to copy this one and set my email, now this is very important. I don't know if it matters whether your username exactly matches GitHub, you probably should have it match. Your email needs to exactly match the email you signed up for GitHub with and I actually signed up with Daniel.Schiffman+rainbow@gmail.com. So I'm going to enter that in. So that should be done and by the way, I'm going to hit clear again, if I want to check to make sure that worked, another command is a Git config list I think. Nope, Git config dash dash list, there we go. So you can see this is listing all of the configuration settings for Git on this local computer and you can see my username and user email is now set. So I should and if I type Git status, whoops I want to go back and hit Git status, so uh, it actually, so we managed to make that commit. It did actually do that commit but it just, it's uh, it's it used like some anonymous username or the username that's on my laptop so that's not good. So one thing it doesn't really matter. You know I'm going to, I'm going to let that be. There's a way, there's an amend command which I could amend my previous commands, commits to be now with my particular username that I am now but what I'm going to do is just make another change and I'm going to say in the key of C major the song is a happy song and I'm going to do Git status. I made a change, I'm going to do Git commit. I want to go back a vine, oops, I want to find that command again Git commit, there it is and adding a happy song. So now I'm going to show you another command that you can use, log. So the command log allows you to see locally the history of your Git commits. To be honest it's much more convenient to look at this stuff on GitHub because you have a nice visual interface for doing that but every once in a while you might want to see that and what I'm actually going to do is type Git log dash two which should show me only the last two commits. Although there only have been two commits so you can see here it is and now you can see the difference, you can see this author is Coding Rainbow Daniel.Schiffman+rainbow@Gmail whereas the author of the first commit is processing. It made some default user based on my computer's law. So you want to, what you want to do is set your username and email before you do that first commit. Okay, oh oh something very important that I didn't show you. You can get into this place, this very dangerous place by accident called Vim. Vim, I'm using Sublime as a text editor, Atom is another nice text editor that you can use, TextEdit is a text editor. Vim is a terminal based command line based text editor and when you type in things like Git log you're actually in this place that you can never get out of. I am in Vim because somehow I'm in this weird text editor thing where it wants me to do stuff that I don't want to do so I can always type colon, shift colon and then type Q to get out of it. So often when Git, if you end up in that text editor you could just, you want to type colon and Q and it will get you out of it. Now you may be, you're a kind of person who wants to use Vim and Vim is I'm sure is a wonderful place for many people but it is also a place of heartache and despair and danger. So, colon Q, colon Q that's the new song for today if you get stuck in Vim land. Now I'm going to type Git status and here we are. Now I'm reaching the end of this particular tutorial video because I've been going on and on and on. What is it that I, what is it that it's missing? Now here, my read me file, here in this particular repository has changes that are not reflected on GitHub itself and you can see that right here, that we're seeing the old read me file here on GitHub. So now I want to talk to you about the concepts of push and pull. I mentioned these concepts when I talked about pull requests so I'm adding to here push and pull. So let's review this, this is GitHub, this is you working locally in your terminal. Pushing is the act of sending to GitHub, pulling is the act of receiving from GitHub. So what I've done is I've worked on my repository here locally and the changes that I've made here no longer exist, are not reflected on GitHub so I want to push to GitHub. When would you want to pull from GitHub? Well maybe somebody else is also working on your repository and they push some changes to GitHub and you don't have those changes on your laptop then you would want to pull, so GitHub being the sort of central place for multiple people to contribute to and you could always push your changes there and pull other people's changes back down to yours, so let's just look at push. Back over here, now here I am again I'm going to say, Git push, huh? It doesn't know what to do. Now I've discovered there's another really key aspect of this, there is another command to add to our list called remote, this is me working on my laptop on my Git repository, GitHub is now an example of a remote, a remote is a duplicate instance of your repository that lives somewhere else on a remote server, you can have multiple remotes for a particular project, in most of the cases into my tutorial videos I'm just going to have one remote, GitHub as that particular remote. So what I need to do is say where, when I say Git push I need to say Git push where? So you might think that what I would say is Git push GitHub because what I want to do is Git pushed to my remote GitHub. Now, it doesn't know what that is. So, it doesn't, it gave me a bunch of error messages. So I'm going to type something, Git remote. Ah, this lists me all the remotes associated with my project one of which is called origin. I can actually also say Git remote dash V the V's meaning verbose and it's showing me more origin is actually this particular URL. So now, I don't want to, I want to say Git push origin so origin is the name of the remote, it's just whatever default name that GitHub and Git used when you clone your repo originally, it just calls it origin, it's the where word, where it came from, it's the origin of this particular repo so Git push origin should be enough, right? Nope gave me some more actually, it didn't give me those error, gave me a lot of a lot of error, a lot of junk, I think it tried to do it with sub default but I'm missing one piece. I need to say the remote which is origin and then I need one more argument which is the branch. See how much more work this is to work locally through terminal, it just, all I did, to do it was commit button on GitHub and I was done but I want to push origin branch master. So I'm just working in the master branch right now, we're going to do fancier stuff with branching and all that sort of thing later. Git push origin master. Git push origin master. Denied to Shiffman, oh you, I'm not Shiffman, I'm RainbowCoder, timeout pause this video tutorial. I'm back and ready to push to GitHub. The reason why I had a problem is I've logged into my computer previously as a different username and it still thought I was that. So I fixed it now and I'm ready to say Git push origin master here we go, Git push origin master, now this is what you should see. Of course it's not going to just let me do this because it doesn't know who I am, you need to, if whether I have access rights to that particular repository on GitHub. Now in fact I do and I should be able to enter in my GitHub username right here and then I should be able to enter in my GitHub password so hopefully I remember right here and hit enter and it happened, there we go. Now you can see it gave me information about the stuff being sent to GitHub and I can go here and I can hit refresh and you can now see the new text is here and if I go under commits you can see here. Now, the good news is remembering this particular commit has an incorrect user name, I didn't go back and fix it because I don't really care, big deal but you can see that this particular commit is assigned to the correct user because my Git settings on my laptop are the same username as my username on GitHub, username and email, okay. So this video turned out to be a little bit less than I originally intended but let me just recap for a second and talk about what I'm going to do in the next one. So, all we did in this video was create a totally new repository on GitHub, cloned it to our laptop made some changes to it and pushed it back and while doing that we realize we have to install Git on the laptop, we have to know about Unix commands and I have to also make sure that my global username and email settings are configured. Once you've done that you're kind of good to go for a much longer period of time and in, because you don't have to do all that again. Just say that I always spent like a half an hour trying to get my username correct if you're watching this that's why I've gotten lost my train of thought here, in the next video I'm going to show you how to make a fresh repository from an existing folder on your computer and send that to GitHub because a lot of cases you might actually have already made something on your computer that you want suddenly turn into a repository on GitHub so I'll show you that not using the Git init command in the next particular video and from there I'm going to keep going with more and more types of things that you might want to do with working with other people's repositories and branching and merging and all sorts of other possible things that you might need to do at some point. Okay, see you in the next video maybe, if you choose to continue to watch.
Info
Channel: The Coding Train
Views: 351,450
Rating: 4.8829136 out of 5
Keywords: git, github, pull, github (website), git (revision control software), tutorial, lesson, coding, github tutorial, git tutorial, repository, branch, pull request, version control, version control tutorial, team programming, teamwork, teamwork coding, commit, repository tutorial, commit tutorial, how to use github, how to use git, how-to (version control), how to setup github, repo, github version control, git remote, git clone, git push pull, git status, git log
Id: yXT1ElMEkW8
Channel Id: undefined
Length: 21min 49sec (1309 seconds)
Published: Wed May 04 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.