Git Pull Requests explained - Computer Stuff They Didn't Teach You #5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey friends I'm Scott Hanselman yesterday I did a git basics or get 101 with my perspective on how you can learn git and today based on your comments I'm going to talk a little bit about pull requests or pr's someone often says send me a PR or would you look at this pull request or would you please merge my pull requests turns out that pull requests aren't really a git thing it's just a convention it's confusing because you think it's part of git but it's really a way of working with git now yesterday if I switch to our picture-in-picture we left ourselves having created a bunch of text files we had a log of the different work that we did with our git repository and I was using Visual Studio code plus one additional extension called git history which is lovely and git history allows you to look at your repository in a graphical way and we created some text files and we branched into a parallel universe a couple of them one was called testing and then we merged back in to the main line and did some work now a pull request is actually just someone else's branch in another world on their computer in a remote world it could be their computer it could be somewhere else one of the things that's interesting about get is where's the authoritative code well the authoritative code is whatever you decide it is git is what's called decentralized source control so there's no rule that says that my code is more important than your code you could have a copy of my repository or a clone of it doing your own thing and it's up to us as a team to decide the convention on what is the official authoritative code and a pull request is just me expressing to you my interest that you look at my code and possibly pull it over to your side it's a request to pull your branch into my world now it's worth also pointing out that when I created this repository I created it locally and I didn't do anything with github or get lab this is a git repository that's just chilling on my machine it's got nothing to do with yet the way I know that is that there are no remotes the concept of a remote connection in my kit is not there sometimes usually if I were to go up here and make a new repository let's actually try this I'll come up to another folder and I'm going to make a new repository and I'm going to call it I will call it learning get to ok I'm gonna make it first at github that's not what I did yesterday yesterday I made a git repository I didn't even talk about github here I'll make it on github I could set up a readme and some different they don't make a readme I guess why not set a license that's probably the responsible thing to do and I could also even pick a language that I might care about for get ignores I'll talk about that in another video and I'll create this repository this is creating the repository in github in the cloud it's not on my computer and I can click on code and I can check out this code I'm going to just copy this into the clipboard here so I've checked out this URL so my repository is a URL I'm gonna go back over to here and I'm gonna say git clone and then I'm gonna right-click and paste in that location so I'm saying hey can I have the repository called learning get to ok cloning into learning get to that's a folder there's my first one from yesterday here's the one from today and there's that license that get ignore and that readme all right so I brought a git repository down to me I cloned it I made a copy it is now in two places it's in github it's on my computer what's the official one what's the boss depends on who decides probably fair to say that this one the github copy is the official source but I could decide that I want this to be the official source there's nothing in get that says otherwise it's me or my team who designs now remember when we said get remote if I say get remote show I say the command get the sub command remote and the sub commands show it says something called origin what's that well get commit show origin says hey there's a named place we just call it origin it's a convention just like master or main as a convention get remote show origin started here it's just a name you might also see other names like upstream that would imply that I am downstream okay there's a fetch URL a place to pull from and it also happens in this case to be the same place that I could push my code from now if we go back over to where we were yesterday learning it and I say git remote show or get remote show origin well there's no there's no origin I could not read from a remote repository that's because when you get in it or create a repository locally like we did yesterday in video one that I would encourage you to check out you'll see that there's no remote I got that remote for free when I did the clone from the one I made in github now if we went back to my main page on github and I made a repository and we called it let's say learning get the same name as the one we made yesterday okay we'll create that and then it says hang on a second are you doing this for the first time do you want and it's giving me commands I could get in it I could add a file but look at this line right here git remote add origin okay that's interesting you can push an existing repository for the command line so I said git remote show not get remote add get remote show I don't have one there's no connection from my git and the one in the cloud so let's try that let's copy paste this just that first line I'm gonna alt tab back here I'm gonna right click and I'm gonna hit enter nothing happens but I'll confirm that it worked because git remote show and more specifically get remote show origin now refer to learning get I've now connected a relationship I've connected they get locally with the git remote except on my local machine or five text files and on the one in the cloud there's nothing now here it says get push - you origin master I can go and learn about what these things mean by saying git push or get remote or whatever and I can say - - help and that will go and launch a web browser and take me there and I can find out what - you does remember that it said hey I'd like you to say push - you that - you refers to this concept called upstream this allows me to track relationships between branches remember how I said that I am downstream now here it says I should push it to a branch called a master but if you remember from yesterday I called mine main you can call yours trunk or dev or production or staging whatever makes you happy so I don't want to say get push origin master I'm going to say get put push origin origin main now before I do that before I hit enter I'm gonna split screen here and I'm gonna bring this over here so what I'm doing is I'm just hitting the Windows key on my Windows machine I'm saying windows right and those left using the button on my keyboard marked Windows and now I'm gonna hit enter on the left hand side here alright here we go get push remote branch main set up to track remote branch mean cool okay so there's a relationship here now okay now over here on this side and this browser here I'm just gonna hit refresh look at that and that cool we took an existing git repository and we now have it talking to the one in github so that's pretty freakin cool we can see that we have a branch called main moreover I can see that there's seven commits hang on seven commits that looks a lot like these commits okay now the only difference is that I have other local branches here okay I have local branches that are not necessarily in the cloud okay so up here I've got main as a branch I could save you all branches but there's nothing in github that knows about my branches like the ones we did yesterday called testing or new feature alright so I can say git branch - a and I can see locally here on my machine that I've got main I've got new feature I've got testing I did those yesterday and now I've got a tracking branch this remote this remote origin up there called main so that's pretty interesting if I wanted to I could push these other branches up into the cloud I could switch over there and have people work on them but it's very common in the get world for someone to be doing just a little bit of work locally here on their own machine for example if you were to clone my get repository yourself on your machine you can do that you would actually fork it you would fork it or split the world into a parallel universe your copy of learning it and then do some stuff maybe make a branch you could name it PR one if you felt like it nothing wrong with that and you could make a pull request then you could tell me via github or any number of ways hey it'd be really cool if you would go and look at my code could I request that you pull my code wouldn't that be nice now someone could do that I could do it myself here if I wanted to I could say create a pull request but I don't have anything to necessarily compare I don't really have a good way to do that because it's saying well can you compare different branches how would I make a pull request if I'm not a another person so I need a friend to make a pull request for me so I'm gonna do that right now I'm going to ask someone to make a copy of this and then make a pull request so a few minutes have passed and I can see that a fork has occurred and I can click on that and I can see that my friend Maggy has made a fork a copy her own copy of the learning gait repository I can click on that and you'll see that it's a her your L doing her own thing she can have her own code but I can see that a pull request has come in just a few minutes ago maggie has said hey can you go and look at some code that I did for you she wants me to pull that code into my space into my area I can click on that within github and you'll notice that it says Maggie wants to merge a commit into Hanselman main and look look at that she named it Maggie patch one she can name it whatever makes her happy because again pull requests are just a construct they're just a way of thinking she says hey I've got a repository over here and you've got a repository could we merge these two repositories together so here's the thing that I want to show you I could merge the pull request in github meaning I would use the tools in github and do a bunch of cool work I could say yeah can you bring this into the base branch that main branch if there were a lot of commits can you squash them into one commit if you have like five things coming in you say yeah that's great give me just the one right or if I'd gone forward into the future and Maggie I hadn't talked to her in a week and she says oh shoot my stuff is great but it's old or could you could you put that on the new stuff could you make a new base did you rebase and then just play back the stuff that I did on yours we'll talk about that in another video but I think it would be more interesting because it's too easy to click merge pull request that's like what's the point how do we learn what if we could look at this locally and in the doing of that better understand git okay so if we look at on the left hand side here I could check out Maggie's pull request so here it says switched to a new branch called Maggie patch main what I did is I made a local one myself okay and then I'm gonna go and pull because she requested a pole so I'm gonna pull from her get pull notice it doesn't say as handsome and it says Maggie and we're gonna pull from her repository not mine into my branch alright cool look at that no I could look at it what's going on okay it looks like she made a change what's this here a different date we've got this this text file now I can open that in notepad or I can open that in whatever makes me happy but I'm gonna open it here and I'm gonna say copy to it looks like oh look at that there's some code from Maggie in this case she added Maggie's test in a text file okay so she made a change and now I can look at it now remember I can say get checkout main watch it's gone I can say git checkout Maggie watch now it's back that's Maggie's branch how did I get it let's remind ourselves I made a branch and I pulled from her git repository now it's local to me now I again I could have done this all and just click merge but again that's driving an automatic shift car and we're learning just a little bit to drive stick to drive a manual shift car okay so now if I wanted to I could go and check out main so I'm back over here Maggie's test is gone above me all right now what are we gonna do is we're gonna merge we're just like we did this at the end of video 1 and again feel free to go back and refer yourself to video 1 what we're gonna do is we're gonna merge in Maggie's patch I'll do this over here at the top make it a little bit bigger there we go we're gonna not fast-forward talked about that a minute there you go so we've now brought this over into me but look at this see my pretty prompt has changed colors now and it says hey you've got two new things and what's this those two new things they need to go up up to the origin upstream somewhere else so I'm gonna go and say get push I'm gonna put those up in the main I'm gonna say get push and that name origin again it can be anything it could be development could be staging origin as a convention a lot of get is just conventions conventions are just ways of people saying and let's make it this way why I was first that's the way it is that's fine we just need to know that these are not necessarily built into get they're just things that people decide like main or origin or Maggie patch one someone decided and that's okay so want to push that up all right cool what's this look at this look what happened in github I didn't even have to hit refresh Hanselman that's me Shan Suleman merged the commits into Maine so Maggie is now an open source contributor if we assume that my text file is open source she has made a pull request and then I can come down into here and I can make a comment congratulating her on editing a text file and I can say great ship it with the ship it squirrel ship it good job okay so my pull request now is closed I've closed that pull request so let's think about this I had a local copy of get of my git repository I connected it up to the origin to something that was either an origin or upstream in this case they're the same and that was in github connected the two could have done it automatically but I chose to do it manually then my friend made a pull request she made a fork made a copy cloned it to her own machine made a change made a branch put that change in the branch told me about it requested I pull it over and I manually pulled it then I merged it just like we did at the end of number two I merged it into main and then I pushed it from my local machine up to the cloud and if we look at this now we can see look Maggie's test and look at this this text file has two contributors you'll see that when you work in a big project with git you'll have dozens of contributors this means everybody was involved which is great and that's why open source is so fun but again you'll notice that Maggie's branch isn't here because Maggie's branch is over in Maggie's repository and now that she's heard that I've gone and done a a merging of her pull request she might delete the branch because it was just a feature or a thing that she was working on so that's the dirty little secret about pull requests it's a it's a convention it's an agreement and how we communicate and we're using git remotes and branches to do that so I hope that this was helpful and thank you Maggie for helping me with my video this is step 2 of the get tutorial that I didn't think I was going to do if this is helpful please leave a comment tell your friends and I guess the kids say smash that Bell subscribe and maybe I'll have a I'll be able to buy a taco with my major YouTube money that we make dozens dozens of dollars that we make with the YouTube thanks friends
Info
Channel: Scott Hanselman
Views: 48,210
Rating: 4.9832482 out of 5
Keywords:
Id: Mfz8NQncwiQ
Channel Id: undefined
Length: 21min 10sec (1270 seconds)
Published: Wed Jul 01 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.