Hey everyone so if you've used Git and GitHub for
source control you may have heard of pull requests. If
you're new to Git check out this video link above.
But for those of you familiar or just want to
learn how to do a simple pull request, I want
to show you how in Visual Studio code with an
extension called GitHub Pull request.
So let's check it out.
To get started, we'll want to install the extension from
the marketplace, and the actual full name of it is
GitHub pull requests and issues. And for brevity, I'll just
refer to it as the GitHub pull request extension, especially
since pull requests are the focus of this video. But
you should know that this extension is capable of reviewing
and creating issues associated with pull requests. Now, I already
have it installed, so we'll just go ahead and
Move on now the other thing that I have set
up is a simple Python file that prints rise and
shine on 2 branches. One is on a working branch
and the other is on a main branch. Why? Well,
because best practices dictate that you don't want to modify
code on your main or base branch, but rather a
different branch so that it could be reviewed before it
is merged. And this leads us to the purpose of
pull requests.
To fully appreciate this extension, we really need to understand
the essence of what a pull request is, and if
we look at the official definition we can see that
it says pull requests let's you tell others about changes
you've pushed to a branch in a repository on GitHub.
Once a pull request is open, you can discuss and
review the potential changes with collaborators and add follow up
commits before your changes are merged into the Base Branch
and that base branch for us is going to be.
Our main branch, and as I mentioned earlier, the branch
that we're going to be making changes on will be
our working branch. So let's just jump into it. So
here on our working branch, we're going to add a
line of code and I'm going to simply print. Let's
get it started, but I'm going to purposely leave an
error. So let me click the source control icon here
and now I will stage this.
And add a description added line of code. We'll commit
this and sync this to GitHub and we are working
on our working branch as a reminder. And if we
were to hop over to GitHub and click on our
working branch and look at our file, we'll see the Of
code that we added.
So back in Visual Studio code, if we click on
the GitHub icon, I'd like to explain there are sections
going from the bottom to the top the bottom. Here
we have the issues which I mentioned earlier that this
extension is capable of doing. We have a section for
my issues, created issues, and recent issues. If you wanted
to create an issue, you can go ahead and click
on this + to do so, but we're not going
to do that since we are focused.
On power requests and over here the sections that are
relevant to you is local pull requests branches which we
currently have zero in right now. Pull requests that are
waiting for my review right below that assigned to me,
created by me, and then finally all open pull requests.
But we don't have any now. So these will say
0, but let's go ahead now and create a pull
request. To create a pull request you can either click
on this pull request.
Icon here or use the shortcut that's right over here.
And essentially the UI describes what our workflow is and
what we want to do is to merge changes from
our working branch into our main branch. And let's just
give a title for our pull request here. Added one
line of code and here we'll put details about our
change and then click create. So what happens here is
that.
Pages launched describing the pull request we just created. Note
that over here it says that this branch has no
conflicts with the base branch. Also note that it is
checked out because we were already on the working branch.
But if I'm a recipient of this pull request, that
is, I need to like review and approve it, I
wouldn't be on this working branch, but probably the main
branch where we want to merge it to.
So let's hop over to the main branch and here
I'm going to check out the pull request. And once
we check out, our pull request is displayed with a
page that has the original code on the left hand
side, and on the right hand side is the code
with the do line that we added. Now what's great
about this extension is that we can actually try to
execute our code to see if there's an issue. So
I'm going to go to our terminal and I'm going
to type in.
Python 3 rise dot PY and as you can see
it does catch our error, which is great because this
way we can test to see if the code definitely
does work before approving it. If it doesn't for any
reason, we go ahead and add a comment explaining it
to the developer so that they could go ahead and
resolve it and then resubmit it. In our case right
now, just simply add a comment that says.
Error in code needs closing parentheses. If we hop over
to GitHub, going to pull requests, clicking on added line
of code, this comic can now be seen and at
this point the developer can fix the code, resubmit it,
and ideally it'll be approved and merged to the main
branch. So to tidy things up, why don't I go
ahead and actually fix the error? I will go ahead
stage and commit this.
Six, we'll sync it to GitHub. Let's look at our
pull request.
And we could see that our changes looked the way
that we expected without any errors.
I'll go ahead and merge the pull requests.
And now on GitHub on our main branch, we have
our final code without any error that's been merged. One
last thing that I want to show you is that
if we go to GitHub and on our pull requests
repository we clicked on pull request, chose this, closed one
and selected added one line. There's an online version of
Visual Studio code that we can jump right into just
by hitting the period.
And by default of the GitHub and issues extension is
embedded in this online version. So as you can see
here, there's GitHub pull request and we can compare the
changes that we made by adding that second line of
code. And on our left hand side we could drop
down to see our different commits that were made. And
if we were to click on the GitHub icon, you
could see our different sections for pull requests and all
the subcategories along with issues.
In its subcategories, and there's even the detection to install
extra extensions. As you can see on the bottom right
hand corner here, it's asking us if we want to
install a Python extension because it detects that Python is
being used. Now to be a little bit more intricate,
I want to show you a bigger project, not just
a simple one. A few years ago I put a
course together that has lots of exercise files in it,
and every once in a while there's a bot that
goes through GitHub and updates the code and generates a
pull request.
And this is an e-mail that I got here. Tell
me about this pull request that is available. So if
I click over here it brings me straight to the
course which is called hands on web development with asp.net
core and Angular 7. As you can see it's a
little bit of an older course, but if I go
right onto pull requests and choose the latest one here
I can hit the period key and pull up Visual
Studio code online.
And immediately it'll show me the different changes that were
made. So if we look on the right hand side,
you could see with the green and pink bars, it
tells us what was changed. So for example over here
we could see like a line of code with integrity
was changed if we go down to some other lines.
We could see where it just one line of code
was added so if I wanted to I can click
on a + here and add a comment looks good.
And do this for like the rest of the code
on the left hand side. Once again if we click
the GitHub icon now we could see all these other
open pull requests. But for now all I'm going to
want to do is click on the pull request icon
click at the top level here bump CSS.
And here is where I have an option to just
approve the pull request at a high level. Looks good
to me.
Click approve and we're done.
Aren't extensions amazing? And this GitHub pull request extension is
a prime example. Let me know in the comments what
your thoughts on it are or any other extension that
just totally blew your mind. If you got value out
of this video, don't forget to hit that like and
subscribe button and also check out some of these other
videos below.