We're going to learn how to make pull requests on GitHub. This will be how you request feedback going forward.
- What Is A Pull Request
- The Submission Flow
- Practicing Pull Requests
- Requesting Code Review
- Merging Pull Request
Pull requests are the main channel multiple developers use to collaborate on a single project. If one developer has changes they want to contribute to a project, they:
- Create a new branch called, e.g.,
cool-feature
- Make any changes they want to add to the main project on that new branch.
- Submit request to merge their changes in
cool-feature
intomaster
— this is the pull request - The team is notified that someone has opened a pull request.
Let's say we're working on the JavaScript Fundamentals I exercises. This would be the flow (we'll share the git commands later):
- Fork the main project/exercise repository to create your own copy
- Start working on an exercise or iteration, e.g., the
isPrime
function. - Create a new branch on your copy and give it a sensible name like
is-prime
- Do the
isPrime
exercises, which might involve many commits, but they all live on theis-prime
branch - Open a pull request to merge
is-prime
into YOUR forks'smaster
branch. - Go to the pull request page and request a code review from an instructor. This is built into GitHub.
The feedback will happen on the pull request.
This process is called the feature branch workflow and is the most commonly used workflow for teams collaborating on a single repository.
- Each new feature starts on its own branch (the so-called feature branch).
- When the feature is ready, a pull request is submitted to merge the feature branch into the
master
branch. - A code review happens
- If something need to be changed based on the review, those
- Once everything looks good, the feature branch is merged into
master
.
We're going to create a pull request that contains two individual commits involving different files.
First, fork this repository to create your own copy.
Next, clone your fork using the git clone
command. This will create a copy of your repository on your computer (called a local copy).
Note: Replace YourGitHubUsername
with your actual GitHub username.
git clone https://github.com/YourGitHubUsername/exercises-git-pull-request.git
This will create a directory named exercises-git-pull-request
inside the current working directory. Enter the directory with the following command:
cd exercises-git-pull-request
When we're inside a git repository, there is always an "active" branch. To see a list of all the branches run:
git branch
The active branch is whichever one is prefixed with *
. Because master
is the only branch, you should see:
$ git branch
* master
$
Let's create a new branch and switch to it. Run the following:
git checkout -b first-feature
Run git branch
again and you should see:
$ git branch
* first-feature
master
$
Note: Remember to use commands like ls
and pwd
to verify you're in the correct directory and looking at the right files.
While on the first-feature
branch, create a file named hello.txt
that contains the following text:
Hello! This is my first pull request.
Make sure to save the file. In the console, run the following command:
git status
This gives you information about the current state of your git repository. It will show you which files have been modified, which files are new and have yet to be committed, etc.
Run the following git add
command:
git add hello.txt
Run git status
again to see how the output changed.
Run the following command to create a new commit:
git commit -m 'hello.txt is a lovely file'
Run git status
and note how the output has changed.
Let's create a second commit.
Create a file named goodbye.txt
that contains the following text:
Goodbye! About to submit my first pull request.
Again, run git status
to see how the output has changed. Add and commit goodbye.txt
.
To add it:
git add goodbye.txt
Run git status
and note how the output changed.
To commit it:
git commit -m 'Time to say goodbye'
Run git status
and note how the output changed.
Right now, your branch exists on your machine but doesn't yet exist on GitHub. To simultaneously push your changes up to GitHub and create the branch on GitHub, run the following command:
git push --set-upstream origin first-feature
Here origin
refers to GitHub.
Now visit your repository on GitHub.com!
On GitHub, you should see the following: https://share.getcloudapp.com/YEud6DE4
Click the Compare & Pull Request. On the next page, click Create Pull Request.
Ta-da, first pull request!
You have two ways to request a code review:
-
Add one or more instructors as collaborators on your project and then select them from the "Request Review" dropdown
-
Leave a comment
@
-mentioning anyone you want a code review from. If you want a review from GitHub userSnorkleFish
then leave a comment that looks like:@SnorkleFish I'd like a review!
Once you're ready to go, merge your pull request into the master
branch. Don't wait for a review to merge unless you think it's critical.