Branches allow you to 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 referred to as a feature branch or topic branch. For more information, see "Creating and deleting branches within your repository."
You can also use a branch to publish a GitHub Pages site. For more information, see "About 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. For more information, see "Access permissions on GitHub."
Ao criar um repositório com conteúdo em your GitHub Enterprise Server instance, GitHub Enterprise Server cria o repositório com um único branch. Este primeiro branch no repositório é o branch-padrão. 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. A menos que você especifique um branch diferente, o branch-padrão em um repositório é o branch de base para novos pull requests e commits de código.
By default, GitHub Enterprise Server names the default branch
main in any new repository.
É possível alterar o branch-padrão para um repositório existente. For more information, see "Setting the default branch."
Você pode definir o nome do branch-padrão para novos repositórios. For more information, see "Managing the default branch for your repositories," "Managing the default branch name for repositories in your organization," and "Enforcing repository management policies in your enterprise."
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). For more information, see "About pull requests."
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"
Se você excluir um branch de cabeçalho após o merge do seu pull request, o GitHub irá verificar se há quaisquer solicitações de pull no mesmo repositório que especificam o branch excluído como o branch base. O GitHub atualiza automaticamente quaisquer pull requests, alterando o branch base para o branch base do pull request mesclado. The following diagrams illustrate this.
Here someone has created a branch called
feature1 from the
main branch, and you've then created a branch called
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
In the next diagram, someone has merged the pull request for
feature1 into the
main 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
Now when you merge the
feature2 pull request, it'll be merged into the
Repository administrators can enable protections on a branch. If you're working on a branch that's protected, you won't be able to delete or force push to the branch. Repository administrators can additionally enable several other protected branch settings to enforce various workflows before a branch can be merged.
Note: 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."
To see if your pull request can be merged, look in the merge box at the bottom of the pull request's Conversation tab. For more information, see "About protected branches."
When a branch is protected:
- You won't be able to delete or force push to the branch.
- If required status checks are enabled on the branch, you won't be able to merge changes into the branch until all of the required CI tests pass. For more information, see "About status checks."
- If required pull request reviews are enabled on the branch, you won't be able to merge changes into the branch until all requirements in the pull request review policy have been met. For more information, see "Merging a pull request."
- If required review from a code owner is enabled on a branch, and a pull request modifies code that has an owner, a code owner must approve the pull request before it can be merged. For more information, see "About code owners."
- If required commit signing is enabled on a branch, you won't be able to push any commits to the branch that are not signed and verified. For more information, see "About commit signature verification" and "About protected branches."
- If you use GitHub's conflict editor to fix conflicts for a pull request that you created from a protected branch, GitHub helps you to create an alternative branch for the pull request, so that your resolution of the conflicts can be merged. For more information, see "Resolving a merge conflict on GitHub."