GitHub Forks and Pull Requests | Step by Step

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys Wes here in this video we're gonna take a look at making github Forks and pull requests if you like videos about full stack web development machine learning and DevOps then I would really appreciate it if you like and subscribe in this video we're going to talk about creating forks and pull requests on github so one of the really important things about open-source is that the software we create in open-source projects is freely distributed and so if you'd like to make a change to an existing open source project you can simply create a copy of that code for yourself and then work work on it on your own if you would like to contribute to a project you can create a copy of that code and then make your changes and then request that those beat changes be merged back into that original project and when we're dealing with open-source projects on github creating a copy of some initial repository is called creating a fork and so in this video we'll look at creating a fork of an existing open source project making some changes and then creating a pull request to actually request that those changes be merged back into that original project one of the really cool things about a pull request is that you can create it early on in the process of making changes to a repository this is particularly useful if you're working on a larger bug fix or a feature request and so what you would do is create a pull request and then kind of share the ideas that you have maybe some early code some early changes and then collaborate with other developers on the project as you work on those fixes so that pull requests user interface really provides a nice way to collaborate with other developers as you're working on changes before those changes actually get approved in and potentially merged back into the master branch of some projects so with that let's dive into some code will use a repository that I set up for this video but you're more than welcome to use it as a practice repository for making Forks and pull requests and if you have any questions at all just be sure to leave them in the comments below all right with that let's take a look at some code okay so our first step here is to visit github and we'll find the project that we would like to fork and for the sake of example here I'm just going to fork a project that I created a couple of months ago which is a Python epidemic simulation I created this at the sort of start of the kovat 19 pandemic and was inspired by some interactive simulations that I saw in the news and I just decided to create a really crude epidemic simulation here in Python so you can check that out but we're really just using this repository for the sake of example so when we're working in open source and in particular here on github and we'd like to make changes to a project say we need to create a bug fix or we'd like to otherwise contribute to some project our first step is really to create a fork and so I'm going to select fork here directly on the project screen and since I have a couple of organizations set up it's going to ask me where should I fork this particular project so I'm going to fork this in to an organizational account here productive for productive dev and we'll see this quick animation while github is forking the project and when that's complete you should see your a user name or organization here slash your repository that you just forked so in this case the Python epidemic simulation which was forked from my personal West Oil account slash Python epidemic simulation so this is now a copy of that original repository and we can make any changes that we'd like to our fork here without worrying about actually affecting that original repository that we forked from so let's say that we would like to make some changes to this particular so the first step that we should do there is simply clone the project so here I'm going to get the URL on the clipboard and then head over to the terminal where we can get clone so we're going to clone this repository down and now I'm going to change directories into that Python epidemic simulation directory and you can see that we're on master branch now the next thing that we should do here is we should configure get so that we're synced with that original repository that we forked from so we have our copy of the repository here in this directory but when we fork from some original project we can configure it so that it will pull changes from that original or upstream repo directly into the local clone that we created when we forked and so to do that what we'll do is we'll head back to github and we'll go to the original project page so this will be the original project that we forked from and we're going to get the URL for this project and then we'll head back to the terminal and then we can actually just take a look at what the current remote is for our fork here and we can view remotes just by typing git remote - V and so here we can see that this is indeed in this case the productive dev fork of that original project and we can see these are labeled as origin but now we're going to add an upstream remote for that original repository and so for that we can type git remote add upstream and then I'm going to paste the original repository belonging to my personal account in this case and now if we type git remote V again I'm going to make the text a bit smaller here so it's easier to see and now if we simply type git remote V again now we can see that we have our origin which belongs to our fork and the upstream which belongs to the original repository that we forked from to begin with and now anytime we actually just want to sync from that original repository it's a pretty simple process we can run git fetch up stream and then if we want to say merge from the upstreams master branch into our Fork we can just simply get checkout master here and now we're on our fork master branch and then we're going to merge upstream slash master and in this case we're already up to date but this would merge the changes from that upstream into our local master branch here and that would in a sense bring what we have in our fork here up to date and in sync with that upstream repository and we wouldn't lose any changes that we have so now let's say we have an idea we want to make some changes to the our fork here and then perhaps we want to propose those changes back up to the upstream and see if they get approved so again this is just kind of a demo project it's not really I don't have any issues open or anything like that but I will show you how you could make a pull request for a project if you were contributing to open source so let's just take a look at the project here and let's say that we made a change to let's just do constants that PI in this case and I'm just going to make some small changes here we'll add some sort of dock strings here all right so we don't need to go through and make any sort of substantial changes here but I will just put a couple of dock strings in on these classes and then so we'll save those changes and then we're going to get status to see the status and we can dip it and just see that we added these two dock strings to these classes so what I'm going to do is get add all git commit and add dock strings and then we're going to get push so now if we head back into github and we're going to go to our fork that we just worked with and we'll take a look at the commits and now we can see that there was a commit that was just made the one for adding dock strings here and then we can see that diff which indeed corresponds to our changes on our fork and so let's say that we were happy with this particular fix or this request and we wanted to create a pull request so what we'll do is we'll head to the original repository and then we're going to select new pull request directly next to the branch drop-down and then we're going to need to select compare across forks because we're going to be comparing across our our fork that we actually created in our account and we'd like to merge that into the base repository from which we actually fork to begin with so since I'm in control of both of these accounts I have a drop down here but we're going to select from my fork here and we're going to open a pull request into the original master branch now we get this nice interface here to create this pull request and we can leave comments for instance and we can preview can use markdown here and there's some other neat features here for instance assigning ourselves to this particular pull request or assigning other users we can also assign reviewers and create labels and assign this pull request of projects and milestones and lots of other sort of project related things that we can work through here notice that we can also see the diff so in this case we only have these docstrings added and if we're satisfied with this then we can just simply create the pull request and so typically if you're working as a developer at an organization you'll have some type of standard process for creating pull requests often code will get reviewed in pull requests but this is just to say that there is typically some type of process so again note now that I am on the original Python epidemic simulation project and since I own this project I can also just here approve the merge request and merge it otherwise I could leave comments so we could do things like look at the files changed and we could even leave comments on particular lines of code for the developer who opened the pull request to to examine and review and then we can click finish our review and in this case I'm going to submit the review with with this single comment and now the author of that could come back and examine the comment and there could be some discussion about the changes made and then the author of the pull request could continue making commits against this branch for which the poll request corresponds and then once everyone is satisfied with the changes that we could then merge this pull request otherwise we could just choose not to merge it in any point in time and close it the merge pull request drop down also has a few other options here including squashing all the commits on this branch into a single commit if there are more than one and then the ability also to rebase and merge ok so here I am going to just show you merging the pull request this will get merged and now we'll see that the pull request has been merged and so if we head back into the the project here we're now on the original repository and indeed we can see that in our constants pie file our changes have now been merged back into that original project so I hope you guys enjoyed this video just kind of a simple demo on how you can fork a project on github and create a pull request across different repositories and then potentially have that pull request merged back into the original project ok so that pretty much wraps up this video as always thanks for watching and I'll see you next time you
Info
Channel: Wes Doyle
Views: 17,275
Rating: undefined out of 5
Keywords: github forks, github tutorial, github pull request, pull request tutorial, git fork vs branch, git fork vs clone, git tutorial, full stack development, learn github, learn github in 15 minutes, git pull request, how to pull request, how to fork a github repository, wes doyle, github, git
Id: a_FLqX3vGR4
Channel Id: undefined
Length: 12min 22sec (742 seconds)
Published: Thu May 28 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.