Movatterモバイル変換


[0]ホーム

URL:


Skip to contentSkip to sidebar
/Blog
Try GitHub CopilotAttend GitHub Universe

Beginner’s guide to GitHub: Creating a pull request

As part of the GitHub for Beginners guide, learn how to create pull requests. This will enable you to suggest changes to existing repositories.

|6 minutes
  • Share:

Welcome back toGitHub for Beginners, a series designed to help you navigate GitHub with ease.

So far in this series, we’ve coveredthe top Git commands every developer should know,how to create repositories,how to upload files and folders to your repository, andhow to add code to your repository. In our most recent entry, we talked briefly about pull requests, but now we’re going to dive into them at depth. This entry is dedicated to showing you how to create a pull request so you can suggest changes to a repository and have others review those changes before committing them.

Let’s get started!

What is a pull request?

A pull request (often referred to as “PR”) is a proposal to merge a set of changes from one branch into another. By creating a pull request, you can review a set of changes with others before they are incorporated into the main code base. Before getting to that, it’s helpful to define a couple of terms.

  • Source branch: the branch containing your changes.
  • Target branch: the branch you are trying to merge your changes into.

Pull requests provide a visual representation of the differences in the content between the source branch and the target branch. This is what enables you to review the changes before accepting them and pulling them into the target branch.

Creating your pull request

You can create a pull request on GitHub.com withGitHub Desktop,GitHub Codespaces, onGitHub Mobile, and when using theGitHub CLI. You can also create a pull request from the terminal usinggit, which is what we’ll do here.

On GitHub, navigate to your repository, clone it, and create a new branch. If you need a refresher for any of these steps, refer to the earlierGitHub for Beginners entries. For the purposes of this walkthrough, we created a new branch in our repository calledupdate-name. After creating this branch, open your terminal and rungit checkout -b update-name to navigate to theupdate-name branch.

terminal showing the git command "git checkout -b update-name"

Open a file in the repository in your editor, and make a change. In our case, we made a change to theindex.html file. Don’t forget to save the file!

Stage and then commit your changes by running the following commands in the terminal:

git add .git commit -m "update game name"

Once these commands are complete, rungit status to ensure that the changes were successfully committed. If they were, you should see a message indicating that there is nothing to commit and your working tree is clean. Awesome!

Now you will need to push your changes to the repository on GitHub. You do this by runninggit push origin update-name in the terminal. Remember that if you used a different name for your branch, you will need to replaceupdate-name with the name of your branch:git push origin your-branch-name.

Navigate to GitHub, and you should see a message indicating that your branch had recent pushes a short while ago. Click the green button that says “Compare & pull request.” This will take you to the pull request page, where you can enter the information for your pull request.

on GitHub dot com with a message that says "update-name had recent pushes 2 seconds ago" with a green compare and pull request button

In the top left of the page is a dropdown button that says “base:” followed by a branch name. Most likely, this will say “base:main.” This indicates the branch that you want to merge the changes into, otherwise known as the target branch. Click the button and select “main” if it isn’t already selected.

The dropdown box to the immediate right of the “base:” box is the “compare:” box. This indicates the branch that you are merging from, otherwise known as the source branch. Click this box and select the branch where you made your changes.

After making sure the target and source branches are set correctly, add a title and a description for the pull request. The description should explain the changes that you made. If you are not ready for your changes to be reviewed, you can create a draft pull request. Or you can create a pull request for review by pressing the green “Create pull request” button. Do that now.

mouse over the green Create Pull Request button on GitHub dot com Pull Request page

Congratulations! You’ve created your pull request! Now, you can have someone else on the team review your changes. Once they have provided a review, you can merge your changes into the target branch by clicking the green “Merge pull request” button at the bottom of the page.

mouse over the green Merge Pull Request button on GitHub dot com Pull Request page

Things to keep in mind

When you create pull requests going forward, here are a few best practices you should keep in mind.

  1. Write small pull requests. Smaller pull requests are easier and faster to review and merge, provide less room to introduce bugs, and provide a clearer history of changes.
  2. Review your own pull request first. Review, build, and test your own pull request before submitting it. This will allow you to catch errors or typos that you may have missed before others start reviewing it.
  3. Provide context and guidance. Write clear titles and descriptions for your pull requests so reviewers can quickly understand what the pull request does. You should include the following in the body of your pull request:
    • The purpose of the pull request
    • An overview of what changed
    • Links to any additional context such as tracking issues, tickets, or previous conversations

Your next steps

Now that you can create pull requests, you can usethis repository to practice creating them. Once you feel comfortable creating pull requests, you have the power to suggest changes to existing repositories and offer your own contributions for consideration. It’s an excellent way to collaborate, so give it a shot!

If you have any questions, pop them in theGitHub Community thread and we’ll be sure to respond.

Here are some more resources to help you on your GitHub journey:


Written by

Kedasha Kerr

Kedasha Kerr

@ladykerr

Kedasha is a Developer Advocate at GitHub where she enjoys sharing the lessons she's learned with the wider developer community. She finds joy in helping others learn about the tech industry and loves sharing her experience as a software developer. Find her online @itsthatladydev.

More onGitHub for beginners

GitHub for Beginners: Code review and refactoring with GitHub Copilot

Learn how to use GitHub Copilot to help review and polish your code.

GitHub for Beginners: Test-driven development (TDD) with GitHub Copilot

See how to use GitHub Copilot to engage in some test-driven development.

Related posts

Career growth

Why developer expertise matters more than ever in the age of AI

AI can help you code faster, but knowing why the code works—and sharpening your human-in-the-loop skills—is what makes you a great developer.

Developer skills

How to create issues and pull requests in record time on GitHub

Learn how to spin up a GitHub Issue, hand it to Copilot, and get a draft pull request in the same workflow you already know.

Developer skills

The difference between coding agent and agent mode in GitHub Copilot

We’ll decode these two tools—and show you how to use them both to work more efficiently.

Explore more from GitHub

Docs

Docs

Everything you need to master GitHub, all in one place.

Go to Docs
GitHub

GitHub

Build what’s next on GitHub, the place for anyone from anywhere to build anything.

Start building
Customer stories

Customer stories

Meet the companies and engineering teams that build with GitHub.

Learn more
GitHub Universe 2024

GitHub Universe 2024

Get tickets to the 10th anniversary of our global developer event on AI, DevEx, and security.

Get tickets

We do newsletters, too

Discover tips, technical guides, and best practices in our biweekly newsletter just for devs.


[8]ページ先頭

©2009-2025 Movatter.jp