記事のバージョン: GitHub.com
ブランチについて
開発作業をリポジトリ内の他のブランチに影響することなく分離するために、ブランチを使ってください。 各リポジトリには1つのデフォルトブランチがあり、複数の他のブランチを持つことができます。 プルリクエストを使えば、ブランチを他のブランチにマージできます。
ここには以下の内容があります:
Were you able to find what you were looking for?
Thank you! Your feedback has been submitted.
Introducing branches
ブランチは以下の目的で利用してください。
- 機能の開発
- バグの修復
- 新しいアイデアの安全な実験
You always create a branch from an existing branch. Typically, you might create a branch from the master branch of your repository. You can then work on this new branch in isolation from changes that other people are making to the repository. A branch you create to build a feature is commonly referred to as a feature branch or topic branch. 詳しい情報についてはリポジトリ内でのブランチの作成と削除を参照してください。
また、GitHub Pagesサイトを公開するためにブランチを使うこともできます。 詳しい情報についてはGitHubPagesと何か?を参照してください。
ブランチの作成、プルリクエストのオープン、プルリクエスト中でのブランチの削除とリストアを行うためには、リポジトリへの書き込みアクセスを持っていなければなりません。 オーナーあるいは管理者アクセスを持っているリポジトリでは、デフォルトブランチを変更できます。 詳しい情報についてはGitHubでのアクセス権限及びリポジトリ内のブランチの管理を参照してください。
Working with branches
Once you're satisfied with your work, you can open a pull request to merge the changes in the current branch (the head branch) into another branch (the base branch). 詳しい情報についてはプルリクエストについてを参照してください。
After a pull request has been merged, or closed, you can delete the head branch as this is no longer needed. You must have write access in the repository to delete branches. You can't delete branches that are directly associated with open pull requests. For more information, see "Deleting and restoring branches in a pull request"
If you delete a head branch after its pull request has been merged, GitHub checks for any open pull requests in the same repository that specify the deleted branch as their base branch. GitHub automatically updates any such pull requests, changing their base branch to the merged pull request's base branch. The following diagrams illustrate this.
Here someone has created a branch called feature1 from the master branch, and you've then created a branch called feature2 from feature1. There are open pull requests for both branches. The arrows indicate the current base branch for each pull request. At this point, feature1 is the base branch for feature2. If the pull request for feature2 is merged now, the feature2 branch will be merged into feature1.
![[Merge pull request] ボタン](/criselda-https-web.archive.org/web/20200614222800im_/https://help.github.com/assets/images/help/branches/pr-retargeting-diagram1.png)
In the next diagram, someone has merged the pull request for feature1 into the master branch, and they have deleted the feature1 branch. As a result, GitHub has automatically retargeted the pull request for feature2 so that its base branch is now master.
![[Merge pull request] ボタン](/criselda-https-web.archive.org/web/20200614222800im_/https://help.github.com/assets/images/help/branches/pr-retargeting-diagram2.png)
Now when you merge the feature2 pull request, it'll be merged into the master branch.
保護されたブランチでの作業
リポジトリ管理者は、ブランチの保護を有効化できます。 保護されたブランチで作業しているなら、ブランチを削除したり、ブランチにフォースプッシュしたりすることはできません。 リポジトリ管理者は、保護されたブランチの他の設定を有効化し、ブランチがマージできるようになる前に様々なワークフローを適用できます。
ノート:リポジトリ管理者は、ブランチの保護で"Include administrators(管理者を含む)"が設定されていなければ、要求を満たしていないプルリクエストを保護が有効化されたブランチにマージできます。
プルリクエストがマージできるかを調べるには、プルリクエストの Conversation(会話)タブの下部にあるマージボックスを見てください。 詳しい情報については保護されたブランチについてを参照してください。
ブランチが保護されていると、以下のようになります。
- ブランチの削除やブランチへのフォースプッシュはできません。
- ブランチでステータスチェック必須が有効化されていると、必要なCIテストがすべてパスするまで、変更をブランチにマージできません。 詳しい情報についてはステータスチェックについてを参照してください。
- ブランチでプルリクエストレビュー必須が有効化されている場合、プルリクエストレビューポリシー中のすべての要求が満たされるまでは、ブランチに変更をマージできません。 詳しい情報についてはプルリクエストのマージを参照してください。
- ブランチでコードオーナーからの必須レビューが有効化されており、プルリクエストがオーナーを持つコードを変更している場合、コードオーナーがプルリクエストを承認しなければ、そのプルリクエストはマージできません。 詳細は「コードオーナーについて」を参照してください。
- ブランチでコミット署名必須が有効化されている場合、署名および検証されていないコミットはブランチにプッシュできません。 詳細は「コミット署名の検証について」および「必須のコミット署名について」を参照してください。
参考リンク
- プルリクエストについて
- GitHub 用語集中のブランチ
- Gitのドキュメンテーション中のブランチの要約
Were you able to find what you were looking for?
Thank you! Your feedback has been submitted.

