Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
GitHub Docs

Contributing to a project

Learn how to contribute to a project through forking.

Platform navigation

About forking

If you want to contribute to someone else's project but don’t have permission to make changes directly, you can create your own copy of the project, make updates, and then suggest those updates for inclusion in the main project. This process is often called a "fork and pull request" workflow.

When you create your own copy (or "fork") of a project, it’s like making a new workspace that shares code with the original project. This is useful for open-source projects or anytime you don’t have write access to the original project.

Once you’ve made your changes in your copy, you can submit them as a pull request, which is a way to propose changes back to the main project. For more information, seeFork a repository.

Creating your own copy of a project

This tutorial usesthe Spoon-Knife project, a test repository that's hosted on GitHub that lets you test the fork and pull request workflow.

  1. Navigate to theSpoon-Knife project athttps://github.com/octocat/Spoon-Knife.

  2. In the top-right corner of the page, clickFork.

    Screenshot of the main page of repository. A button, labeled with a fork icon and "Fork 59.3k," is outlined in dark orange.

  3. Under "Owner," select the dropdown menu and click an owner for the forked repository.

    Note

    If your username is grayed out, it's because the fork already exists. Instead, you should bring your existing fork up to date. For more information, seeSyncing a fork.

  4. By default, forks are named the same as their upstream repositories. Optionally, to further distinguish your fork, in the "Repository name" field, type a name.

  5. Optionally, in the "Description" field, type a description of your fork.

  6. Optionally, selectCopy the DEFAULT branch only.

    For many forking scenarios, such as contributing to open-source projects, you only need to copy the default branch. If you do not select this option, all branches will be copied into the new fork.

  7. ClickCreate fork.

Note

If you want to copy additional branches from the upstream repository, you can do so from theBranches page. For more information, seeCreating and deleting branches within your repository.

Cloning a fork to your computer

You've successfully forked the Spoon-Knife repository, but so far, it only exists on GitHub. To be able to work on the project, you will need to clone it to your computer.

You can clone your fork with the command line, GitHub CLI, or GitHub Desktop.

  1. On GitHub, navigate toyour fork of the Spoon-Knife repository.

  2. Above the list of files, click Code.

    Screenshot of the list of files on the landing page of a repository. The "Code" button is highlighted with a dark orange outline.

  3. Copy the URL for the repository.

    • To clone the repository using HTTPS, under "HTTPS", click.

    • To clone the repository using an SSH key, including a certificate issued by your organization's SSH certificate authority, clickSSH, then click.

    • To clone a repository using GitHub CLI, clickGitHub CLI, then click.

      Screenshot of the "Code" dropdown menu. To the right of the HTTPS URL for the repository, a copy icon is outlined in dark orange.

  4. OpenTerminalTerminalGit Bash.

  5. Change the current working directory to the location where you want the cloned directory.

  6. Typegit clone, and then paste the URL you copied earlier. It will look like this, with your GitHub username instead ofYOUR-USERNAME:

    git clone https://github.com/YOUR-USERNAME/Spoon-Knife
  7. PressEnter. Your local clone will be created.

    $gitclone https://github.com/YOUR-USERNAME/Spoon-Knife>Cloning into `Spoon-Knife`...>remote: Counting objects: 10,done.>remote: Compressing objects: 100% (8/8),done.>remove: Total 10 (delta 1), reused 10 (delta 1)>Unpacking objects: 100% (10/10),done.

Note

To learn more about GitHub CLI, seeAbout GitHub CLI.

To create a clone of your fork, use the--clone flag.

gh repo fork REPOSITORY --clone=true
  1. In theFile menu, clickClone Repository.

    Screenshot of the menu bar on a Mac. The "File" dropdown menu is expanded, and the "Clone Repository" option is highlighted with an orange outline.

    Screenshot of the "GitHub Desktop" menu bar on Windows. The "File" dropdown menu is expanded, and the "Clone Repository" option is outlined in orange.

  2. Click the tab that corresponds to the location of the repository you want to clone. You can also clickURL to manually enter the repository location.

    Screenshot of the "Clone a repository" window. At the top of the window, "GitHub.com", "GitHub Enterprise" and "URL" tabs are outlined in orange.

  3. From the list of repositories, click the repository you want to clone.

    Screenshot of the "Clone a repository" window. The "github/docs" repository is highlighted with an orange outline.

  4. To select the local directory into which you want to clone the repository, next to the "Local Path" field, clickChoose... and navigate to the directory.

    Screenshot of the "Clone a repository" window. A button, labeled "Choose", is highlighted with an orange outline.

  5. At the bottom of the "Clone a Repository" window, clickClone.

Creating a branch to work on

Before making changes to the project, you should create a new branch and check it out. By keeping changes in their own branch, you follow GitHub flow and ensure that it will be easier to contribute to the same project again in the future. SeeGitHub flow.

git branch BRANCH-NAMEgit checkout BRANCH-NAME
git branch BRANCH-NAMEgit checkout BRANCH-NAME

For more information about how to create and manage branches in GitHub Desktop, seeManaging branches in GitHub Desktop.

Making and pushing changes

Go ahead and make a few changes to the project using your favorite text editor, likeVisual Studio Code. You could, for example, change the text inindex.html to add your GitHub username.

When you're ready to submit your changes, stage and commit your changes.git add . tells Git that you want to include all of your changes in the next commit.git commit takes a snapshot of those changes.

git add .git commit -m "a short description of the change"
git add .git commit -m "a short description of the change"

For more information about how to stage and commit changes in GitHub Desktop, seeCommitting and reviewing changes to your project in GitHub Desktop.

When you stage and commit files, you essentially tell Git, "Okay, take a snapshot of my changes!" You can continue to make more changes, and take more commit snapshots.

Right now, your changes only exist locally. When you're ready to push your changes up to GitHub, push your changes to the remote.

git push
git push

For more information about how to push changes in GitHub Desktop, seePushing changes to GitHub from GitHub Desktop.

Making a pull request

At last, you're ready to propose changes into the main project! This is the final step in producing a fork of someone else's project, and arguably the most important. If you've made a change that you feel would benefit the community as a whole, you should definitely consider contributing back.

To do so, head on over to the repository on GitHub where your project lives. For this example, it would be athttps://github.com/<your_username>/Spoon-Knife. You'll see a banner indicating that your branch is one commit ahead ofoctocat:main. ClickContribute and thenOpen a pull request.

GitHub will bring you to a page that shows the differences between your fork and theoctocat/Spoon-Knife repository. ClickCreate pull request.

GitHub will bring you to a page where you can enter a title and a description of your changes. It's important to provide as much useful information and a rationale for why you're making this pull request in the first place. The project owner needs to be able to determine whether your change is as useful to everyone as you think it is. Finally, clickCreate pull request.

Managing feedback

Pull requests are an area for discussion. Don't be offended if the project owner rejects your pull request, or asks for more information on why it's been made. Even if the project owner chooses not to merge your pull request, your changes still exist in your fork. It could be that someone else will find your fork much more valuable than the original project.

Finding projects

You've successfully forked and contributed back to a repository. Go forth, andcontribute some more! For more information, seeFinding ways to contribute to open source on GitHub.

Familiarizing yourself with a project

If you're new to a project, you can use Copilot to help you understand the purpose of the repository, examine files, and dive into specific lines of code. SeeUsing GitHub Copilot to explore projects.


[8]ページ先頭

©2009-2025 Movatter.jp