Now that you have made some changes in the project locally, let's learn how to push your changes back to the shared class repository for collaboration.
In this case, our remote is GitHub.com, but this could also be your company's internal instance of GitHub Enterprise.
To push your changes to GitHub, you will use the command:
$ git push
When you push, you will be asked to enter your GitHub username and password. If you would like Git to remember your credentials on this computer, you can cache your credentials using:
git config --global credential.helper wincred
git config --global credential.helper osxkeychain
Pull Requests are used to propose changes to the project files. A pull request introduces an action that addresses an Issue. A Pull Request is considered a "work in progress" until it is merged into the project.
Now that you have started to change your file, you will open a pull request to discuss the file with your team mates. Follow these steps to create a Pull Request in the class repository:
- Click the Pull Request tab.
- Click New Pull Request.
- In the base dropdown, choose
- In the compare dropdown, choose your branch.
- Type a subject line and enter a comment.
- Use markdown formatting to add a header and a checklist to your Pull Request.
- Include one of the keywords:
resolvesfollowed by the issue number you created earlier to note which Issue the Pull Request should close. Example:
This resolves #3
- Click Preview to see how your Pull Request will look.
- Assign the Pull Request to yourself.
- Click Create pull request.
When you navigate to the class repository, you should see a banner at the top of the page indicating you have recently pushed branches, along with a button that reads Compare & pull request. This helpful button will automatically start the pull request process between your branch and the repository's default branch.
Now that we have created a Pull Request, let's explore a few of the features that make Pull Requests the center of collaboration:
Similar to the discussion thread on an Issue, a Pull Request contains a discussion about the changes being made to the repository. This discussion is found in the Conversation tab and also includes a record of all of the commits made on the branch as well as assignments, labels and reviews that have been applied to the pull request.
The commits view contains more detailed information about who has made changes to the files. Clicking each commit ID will allow you to see the changes applied in that specific commit.
The Files changed view allows you to see cumulative effect of all the changes made on the branch. We call this the
diff. Our diff isn't very interesting yet, but as we make changes your diff will become very colorful.
To provide feedback on proposed changes, GitHub offers three levels of commenting:
You can provide general comments on the Pull Request within the Conversation tab.
In the files changed view, you can hover over a line to see a blue
+ icon. Clicking this icon will allow you to enter a comment on a specific line. These line level comments are a great way to give additional context on recommended changes. They will also be displayed in the conversation view.
When you are making line comments, you can also choose to Start a Review. When you create a review, you can group many line comments together with a general message: Comments, Approve, or Request Changes. Reviews have special power in GitHub when used in conjunction with protected branches.
One of the best ways to ensure code quality is to make peer reviews a part of every Pull Request. Let's review your partner's code now:
- Click the Pull Request tab.
- Use the Author drop down to locate your partner's pull request.
- Click the Files Changed tab.
- Hover over a single line in the file to see the blue +. Click the + to add a line comment.
- Comment on the line and click Start review.
- Repeat these steps to add 2-3 comments on the file.
- Click Review in the top right corner.
- Choose whether to Approve or Request changes
- Enter a general comment for the review.
- Click Submit review
- Click the Conversation view to check out your completed review.