Skip to main content

Managing branches within your repository

Create new branches for development and delete unused branches directly on GitHub.

在本文中

Creating a branch

Create a branch for a separate place to work on changes before opening a pull request.

注意

You can only create a branch in a repository to which you have write access.

Creating a branch via the branches overview

  1. 在 GitHub 上,导航到存储库的主页面。

  2. 在左侧的文件树状视图中,选择 分支下拉菜单,然后单击“View all branches”****。 还可以在集成的文件编辑器顶部找到分支下拉菜单。

    存储库的文件树视图的屏幕截图。 分支的下拉菜单已展开,并用深橙色框出。

  3. Click New branch.

    Screenshot of the "Branches" page for a repository. A green button, labeled "New branch", is highlighted with an orange outline.

  4. Under "Branch name", type a name for the branch.

  5. Under "Branch source", choose the repository and branch to base your new branch on.

  6. Click Create branch.

Creating a branch using the branch dropdown

  1. 在 GitHub 上,导航到存储库的主页面。

  2. Select the branch dropdown menu, in the file tree view or at the top of the integrated file editor.

    Screenshot of the file tree view for a repository. A dropdown menu for branches is outlined in dark orange.

  3. Optionally, to create the new branch from a branch other than the default branch of the repository, click another branch. Then, select the branch dropdown menu again.

  4. In the "Find or create a branch..." text field, type a unique name for your new branch, then click Create branch.

    Screenshot of the branch selector dropdown menu. "Create branch: new-branch" is highlighted with an orange outline.

Creating a branch for an issue

You can create a branch to work on an issue directly from the issue page. See 创建分支以处理问题.

Deleting a branch

Delete branches that you no longer need, such as branches for merged or closed work.

您可以设置在仓库中合并拉取请求后自动删除源分支。 请参阅“管理分支的自动删除”。

注意

If the branch you want to delete is the repository's default branch, choose a new default branch first. See 更改默认分支.

If the branch is associated with an open pull request, merge or close the pull request before deleting the branch.

  1. 在 GitHub 上,导航到存储库的主页面。

  2. 在左侧的文件树状视图中,选择 分支下拉菜单,然后单击“View all branches”****。 还可以在集成的文件编辑器顶部找到分支下拉菜单。

    存储库的文件树视图的屏幕截图。 分支的下拉菜单已展开,并用深橙色框出。

  3. Next to the branch that you want to delete, click .

    Screenshot of a branch in the branch list. A trash icon is highlighted with an orange outline.

  4. If the branch is associated with at least one open pull request, deleting the branch closes the pull requests. Read the warning, then click Delete.

如果您在拉取请求合并后删除头部分支,GitHub 会检查将已删除分支指定为基础分支的同一仓库中的任何开放拉取请求。 GitHub 将自动更新任何此类拉取请求,将其基础分支更改为合并的拉取请求的基础分支。 See Branches.

Further reading