1.10: Git Remotes – Git and GitHub for Poets
Articles,  Blog

1.10: Git Remotes – Git and GitHub for Poets


(dinging) – Hello, this is another video, which is a tutorial about working with git and GitHub, and in this tutorial, I’m going to talk about remotes. (laughs) So, I’m in the middle of livestreaming and I’m working on this project that has to do with
this Flappy Bird clone, and I’m going to train a bot
using a genetic algorithm and a neural network to play Flappy Bird, and I have a wonderful pull request from GitHub user KeeghanM, who has added this particular image to be the Flappy Bird, and
this particular background to be the background of
the Flappy Bird game. I really want to accept this pull request, but what I want to do,
and I can examine it through the GitHub interface, I can see, ah, this was deleted and this was added ’cause now it’s going to have an image, and there’s an icon variable
which loads the image. Those are some wonderful things like that that I want to accept, but I don’t have any unit testing, and this isn’t hosted anywhere, so I want to actually really look at it locally on my computer to run the code and sort of see before I merge it. There’s a variety of ways
that this can be done more efficiently than what I’m going to show you right now, but this is a good excuse to talk about remotes. What is a remote? So right now, my terminal window, which I want to make a little bit bigger, is in the directory of this project. I am on the desktop, Flappy Bird Clone. If I say git remote, that will run this command, dash
V, dash V for verbose, like I want to know as much as possible. I want to be very
verbose about the remote. It’s going to say oh
look, you have a remote that is named origin that is tied to this URL, and that makes sense. That’s my GitHub URL,
CodingTrain/Flappy-Bird-Clone. That’s the GitHub repository. This remote was automatically created because at some point in time I said git clone and I put this in. When I did this, this
default remote was created, so the remote being another location where this git repository exists. The word origin is kind
of a default convention for the original remote,
sort of canonical remote being GitHub in this case,
but it’s just a made up thing. I can say git remote,
and I do this actually with a lot of projects, I can say git remote delete, I think, origin. Nope, git remote remove origin, yes. Now if I say git remote -v, there’s no more remotes, but I could say git remote add and instead
of calling it origin, why not call it GitHub or unicorn? I can call it anything I want. Let’s call it GitHub
and then I can paste in Flappy Bird Clone, I’m just going to grab this URL here and I
can paste this in here. Now I am adding this remote and I can say git remote -v again, and we can see there it is back but
it’s now called GitHub, so if I ever say git pull origin master to grab some changes, master by the way is this name of the core branches, also just a completely made up thing. I can could have source branch or release branch or development branch or experimental branch. That’s a separate video about branches that you can go and watch, but if I say this, it’ll say ah, origin doesn’t appear to to be a git repository because it’s not there, but I can now say git pull GitHub master and, there we go. Now I’m already up to date, so I don’t have to worry about it. Here’s the thing, I want, let’s go back to this pull request which is once again from KeeghanM. So where is KeeghanM’s, we can see here, ah, KeeghanM:graphics, so KeeghanM made these code changes in a branch called graphics in
their GitHub repository. One thing I’m going to
do is I’m just going to copy paste this right here, there’s probably a way I can go in to it and I’m going to go up to the URL and I’m going to change
coding train to KeeghanM. I’m going to get rid of the pull address. I just want to go over there and see that this is the fork of the repository. There we can see this is KeeghanM’s fork. We can see branch master,
we can see branch graphics. I can start looking around. Now what I’m going to do is I’m going to go to clone and I’m going to grab this. I’m now going to grab KeeghanM’s fork of my Flappy Bird clone,
I’m going to grab that and I’m going to say
git remote add Keeghan, I can make up anything here. I’m just going to say Keeghan ’cause I think I can remember
that, and I’m going to then paste in that
particular URL for KeeghanM. One thing you might notice, these URLs say [email protected] You might actually, and this is because I have set up this very fancy way for my computer to be auto logged in with an SSH key and a passphrase, but if you don’t have that set up and I should do a video tutorial that explains how to do that, you might want to use HTTPS, this is also a way, this is just the sort of standard URL without having the sort of secret keys that log you in automatically, but that’s a little bit of an aside here. I’m going to add this remote, and now I’m going to say git remote -v and we can see, look at this, I have GitHub remote which is tied to me at CodingTrain, I
have Keeghan’s remote, which is tied to KeeghanM, which is tied to the GitHub repository KeeghanM. Now I’m going to say, there’s a lot of different things I can
do, but what I’m going to do is I’m just going to
say git branch graphics. I’m going to make a branch
locally called graphics and I’m going to quickly
go into that branch. Again, you should probably watch my branches tutorial about how this works. I’m going to go into that
branch by using checkout. Then what I’m going to
do is I’m going to say git pull, and usually I
almost reflectively just git pull origin master,
git pull origin master, git pull origin master,
git pull origin master, git pull origin master, but I don’t want to pull from origin, I
want to pull from Keeghan. I don’t want to pull from master, I want to pull from graphics. Git pull Keeghan graphics. Ah, ooh, interesting, hmm. So something has happened here in that I have now been launched
into a text editor known as VI, whoa, this has been like way off the screen, that’s
what’s going on here. That’s crazy, and so there’s some sort of merging that needs to happen for KeeghanM’s branch graphics to come into my branch graphics, because I had actually made some other changes. It would have been nice
if this didn’t happen, but this is actually quite normal, this is a regular thing, and
I have to deal with this. What I want to do is say that, I’m going to say, what do I type in VI? (laughs) This always happens to me. I think I say :insert, no. I for insert, I for insert. Again, you can link a
different text editor to your git work on your computer, but this is, now that I’ve been launching this text editor, I just want to say I’m making a tutorial
video so I don’t have a lot of time but this is here to merge Keeghan’s graphics with
some recent changes I made. Then I’m going to say colon, whoops, I got to get rid of insert, escape maybe? Escape, :qw, which I think will then quit and write this out, I don’t really know how to use VI. (laughs) Whatever I meant to call it, :qw and I’m going to just do that,
no, not an editor command. :wq, write and then quit? There we go, and now it’s fine. It didn’t commit it, that’s fine. Now this is good, I just really wanted to look at it, all I wanted to do is look at it, I don’t need to commit this right now because I’m not
really worrying about merging. Now I should, if I come over here, this is me looking at
my code in the browser before I checked out and pulled from that other remote and there we go. Look at this, and now
we have the CodingTrain, Flappy Bird, Flappy CodingTrain game with our little unicorn train
and the scrolling background. Okay, wonderful, so this is good. Now I feel, I’m like oh,
this looks great, I’m done. Interestingly enough, if I wanted to, I could actually merge everything right now from the command line. Normally I would just
go to the pull request and I would scroll down here and I would just click on merge and this would merge that pull request. In fact I can write a comment, thank you so much, I
am going to merge this. What’s wonderful about
using GitHub as a service, which is very different from
the git software itself, the version control software, is that it provides a visual interface to a lot of the common things that you might want to do like merging and looking at the differences between two files and that sort of thing. But I think while I’m here, if you can tolerate to continue to watch this video, however I am going to demonstrate merging from the command line for a fun, so stay tuned. I’m going to add that comment,
so I added that comment and now I’m going to
return to the command line. I should say that something about the way, I really need to make a video about setting up terminal or whatever you use as your
terminal application to work with git more effectively because there’s no
reason why I couldn’t see things being syntax highlighted or showing me what branch I’m currently on and there’s also like
other terminal software like iTerm that I can use, so I’ve got to come back for that, but right now I don’t even remember where I am, so I’m going to say git status and I’m going to say
okay, all conflicts fixed but you are still merging. I didn’t actually ultimately commit that merge that I did, so
I’m going to say git commit. Here’s the thing, I have learned recently that using -m is not as thoughtful, I’m going to do a video about how to not use -m and write more thoughtful, longer commit messages,
but for lack of the time right now, I’m just going to say commit -m and I’m going to say merging changes from and I’m going to want
to remember KeeghanM, from KeeghanM, okay I’m going to do that. I’m going to say git status again. On branch graphics, so now
I’m going to go to master, and what I’m going to
do is I’m going to say git merge graphics and
what that will do is it’ll take the graphics branch
and merge it into master. It’s exactly the same thing that would happen if I
pressed this button here, which would merge
KeeghanM:graphics into master. I’m just going to do that
from the command line. Git merge graphics, okay. Here we go. I’m getting some good feedback in the chat of other things to mention. Yay, okay, it’s merged and now I can say git status, I’m going to say git status, I type git
status all the time. One branch master, nothing to commit, working directory clean, alright. So now let me put these
changes back, right? They’re here on master
but they are not here. If I go here, we’ll see
what’s the latest commit? It’s still something else
that I was working on. I’m going to now say git push, I’m not going to say origin,
I’m not going to say origin, because I renamed it to GitHub, master. If I do that, now I have sent that up. I’m going to hit refresh here and I’m going to see,
look, all of those changes from KeeghanM are now here. We can see they’re here
back on version three. This was me merging, this was me correcting the mistake, this was some other stuff, some other stuff. We can see all of that is here. Now the real question is
if I go into pull requests, look at this, where is that pull request? It’s not there anymore. GitHub is smart enough to realize that I merged this via the command line. The merge button is gone
and it is now in closed. Wonderful, so hopefully
you learned something a little bit about git remotes and about merging in this video tutorial. Thanks for watching and I will come back and make many more of these working with git and GitHub open
source tutorial thingies. Thank you. (dinging) (upbeat music)

46 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *