Skip to main content

Branches

Use branches in GitHub to isolate development work, manage default branches, and collaborate effectively using pull requests and branch protections.

About branches

Branches let you develop features, fix bugs, or safely experiment with new ideas in a contained area of your repository.

You always create a branch from an existing branch. Typically, you might create a new branch from the default 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 called a feature branch or topic branch. See Managing branches within your repository.

You can also use a branch to publish a GitHub Pages site. See GitHub Pages란?.

You must have write access to a repository to create a branch, open a pull request, or delete and restore branches in a pull request. See GitHub 대한 액세스 권한.

About the default branch

GitHub에 콘텐츠가 있는 리포지토리를 만들면 GitHub가 단일 분기로 리포지토리를 만듭니다. 리포지토리의 이 첫 번째 분기는 기본 분기입니다. The default branch is the branch that GitHub displays when anyone visits your repository. The default branch is also the initial branch that Git checks out locally when someone clones the repository. 다른 분기를 지정하지 않는 한 리포지토리의 기본 분기는 새 끌어오기 요청 및 코드 커밋의 기본 분기입니다.

By default, GitHub names the default branch main in any new repository.

기존 리포지토리의 기본 분기를 변경할 수 있습니다. 자세한 내용은 기본 분기 변경을(를) 참조하세요.

새 리포지토리의 기본 분기 이름을 설정할 수 있습니다. 자세한 내용은 리포지토리의 기본 분기 이름 관리, 조직의 리포지토리에 대한 기본 분기 이름 관리, 엔터프라이즈에서 리포지토리 관리 정책 적용을(를) 참조하세요.

Working with protected branches

Protected branches help maintainers enforce rules on important branches. A protected branch can block force pushes or deletion, require status checks, require reviews, require code owner approval, or require signed commits before changes can merge.

These protections help teams keep important branches stable and make expectations clear before a pull request is merged. To see whether your pull request can be merged, check the merge box at the bottom of the pull request's Conversation tab. See 보호된 분기 정보.

참고

If you're a repository administrator, you can merge pull requests on branches with branch protections enabled even if the pull request does not meet the requirements, unless branch protections have been set to "Include administrators."

Comparing branches in pull requests

A pull request compares the proposed changes on the head branch with the base branch. When you create your pull request, you can change the base branch that you're comparing your changes against. The Files changed tab shows what would change if the pull request merged.

Diff views help reviewers understand the changes without reading every commit. You can view a unified diff, split diff, rich diff, or source diff; ignore whitespace changes; or filter files to focus on the most relevant changes.

Screenshot of the "Files changed" tab for a pull request. The "Diff view" menu is outlined in dark orange.

Diffs may not display if a pull request exceeds repository diff limits or if a file is hidden by a rule in the repository's .gitattributes file. See 리포지토리 제한 and 변경된 파일이 GitHub 표시되는 방식 사용자 지정.

Three-dot and two-dot Git diff comparisons

The git diff command supports two comparison methods. Pull requests on GitHub show a three-dot diff.

MethodCommandWhat it compares
Three-dotgit diff A...BThe most recent common commit of both branches (merge base) and the most recent version of the topic branch.
Two-dotgit diff A..BThe most recent state of the base branch (for example, main) and the most recent version of the topic branch.

A two-dot diff compares two Git committish references, such as SHAs or OIDs (Object IDs), directly with each other. On GitHub, the Git committish references in a two-dot diff comparison must be pushed to the same repository or its forks.

See Git diff options from the Pro Git book site.

About three-dot comparison on GitHub

Because the three-dot comparison uses the merge base, it focuses on "what a pull request introduces."

When you use a two-dot comparison, the diff changes when the base branch is updated, even if you haven't made any changes to the topic branch. A two-dot comparison also focuses on the base branch, which can make the changes introduced by the topic branch harder to understand.

In contrast, a three-dot comparison keeps showing the changes introduced by the topic branch since the branches diverged.

Merging often

To avoid confusion, merge the base branch (for example, main) into your topic branch frequently. When you merge the base branch, the diffs shown by two-dot and three-dot comparisons are the same. We recommend merging a pull request as soon as possible. This encourages contributors to make pull requests smaller, which we recommend in general.

Further reading