GIT for Beginners

Initialize Remote Repositories

Pull Requests

When collaborating in a team, it is considered a best practice to use pull requests instead of merging changes directly into the master branch. Pull requests enable team members to review changes, discuss improvements, and ensure code quality before integration. This guide explains how to push your changes to GitHub and create a pull request.

Pushing Your Changes

Before creating a pull request, push your latest changes to the branch you're working on. For instance, if your branch is named "sarah", execute the following command in your terminal:

git push origin sarah

After pushing, GitHub will display a notification indicating that the master branch is one commit behind the "sarah" branch. This reminder serves as your cue to open a pull request to merge the changes.

Creating a Pull Request

Initiate the pull request process by clicking the pull request button in the top navigation bar, or by using the prompt from the notification pop-up. GitHub will then present a comparison view between the "sarah" branch and the master branch, showcasing the changes made.

Tip

Ensure that you review the differences carefully before proceeding. Providing a detailed title, description, and appropriate labels can help your team understand the purpose of your changes.

Let's create a pull request:

The image shows a GitHub interface comparing changes between branches, with one commit adding a file titled "second_story.md."

On the pull request page, you can include additional information about your submission such as the title, detailed description, and relevant labels. You can also assign reviewers who will examine and comment on your changes.

The image shows a GitHub interface for creating a pull request, with a description "Added second story" and options for reviewers, assignees, and labels.

Reviewing and Merging

Once the pull request is submitted, your team members can review the modifications and provide feedback. When the changes are approved, you can merge them into the master branch by clicking the "Merge pull request" button. This process avoids the need to check out the master branch locally, as the merge is performed directly on GitHub.

The image shows a GitHub pull request titled "Added second story," indicating a merged commit from a branch named "sarah" into "master" with a comment section.

Important

In larger teams or enterprise environments, merging into the master branch may require specific permissions. If you encounter restrictions, consult with a team member who has the necessary access rights.

By using pull requests, you not only streamline the code review process but also maintain a well-documented history of changes. This approach is essential for efficient team collaboration and high-quality code integration.

Watch Video

Watch video content

Practice Lab

Practice lab

Previous
Cloning remote repositories