> For the complete documentation index, see [llms.txt](https://cumbucadev.gitbook.io/github-essentials/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cumbucadev.gitbook.io/github-essentials/dia-4/trabalhando-com-branches-localmente/gerenciando-branches-via-git-branch.md).

# Gerenciando Branches via \`git branch\`

O comando <mark style="color:purple;">git</mark> <mark style="color:orange;">branch</mark> é usado para gerenciar branches no Git, permitindo a criação de novas ramificações, listagem das existentes e remoção de branches que não são mais necessários.

## **Suas Três Funcionalidades**

### **Criar um novo branch**

Quando você deseja desenvolver uma nova funcionalidade ou corrigir um bug sem interferir no código principal, você pode criar um novo branch usando <mark style="color:purple;">git</mark> <mark style="color:orange;">branch</mark>.

O branch criado começa com todo o conteúdo do branch atual. Ou seja, o novo branch será uma cópia exata do estado atual do branch de onde foi criado, incluindo arquivos e alterações não comitadas.

### **Listar branches existentes**

Para visualizar todos os branches disponíveis no repositório, o comando <mark style="color:purple;">git</mark> <mark style="color:orange;">branch</mark> pode ser usado sem argumentos.

### **Excluir um branch**

Quando um branch não é mais necessário, ele pode ser removido para manter o repositório organizado.

## **Estrutura**

O formato base do comando <mark style="color:purple;">git</mark> <mark style="color:orange;">branch</mark> é:

> <mark style="color:purple;">git</mark> <mark style="color:orange;">branch</mark> <mark style="color:blue;">\[opções]</mark> <mark style="color:green;">\[nome-do-branch]</mark>

## **Exemplos de uso**

* Criar um novo branch:
  * <mark style="color:purple;">git</mark> <mark style="color:orange;">branch</mark> <mark style="color:green;">feature-x</mark>
  * Cria um novo branch chamado `feature-x`, mas não muda para ele automaticamente. Permanece no mesmo branch que já estava.
* Listar branches existentes:
  * <mark style="color:purple;">git</mark> <mark style="color:orange;">branch</mark>
  * Exibe todos os branches locais, destacando o branch atual com um `*`.
* Excluir um branch local:
  * <mark style="color:purple;">git</mark> <mark style="color:orange;">branch</mark> <mark style="color:blue;">-d</mark> <mark style="color:green;">feature-x</mark>
  * Remove o branch `feature-x` se ele já foi mesclado (*merged*). Ou seja, o branch somente será deletado se todas as alterações feitas já foram integradas ao branch principal.
  * Caso o branch ainda tenha alterações não mescladas e você queira removê-lo de qualquer forma, utilize o comando:
    * <mark style="color:purple;">git</mark> <mark style="color:orange;">branch</mark> <mark style="color:blue;">-D</mark> <mark style="color:green;">feature-x</mark>
    * Isso **força** a exclusão do branch, descartando qualquer alteração que ainda não tenha sido integrada ao branch principal.

O comando <mark style="color:purple;">git</mark> <mark style="color:orange;">branch</mark> é essencial para um fluxo de trabalho eficiente no Git, permitindo que diferentes funcionalidades sejam desenvolvidas separadamente sem afetar o código principal.

{% hint style="warning" %}
Esta é uma explicação simplificada para fins didáticos. Para explorar todas as possibilidades do comando <mark style="color:purple;">`git`</mark><mark style="color:orange;">`branch`</mark>, consulte a [documentação oficial](https://git-scm.com/docs/git-branch/pt_BR).
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://cumbucadev.gitbook.io/github-essentials/dia-4/trabalhando-com-branches-localmente/gerenciando-branches-via-git-branch.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
