> For the complete documentation index, see [llms.txt](https://favelaware.gitbook.io/favelaware/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://favelaware.gitbook.io/favelaware/3-git-e-github/3.5-branches-e-merges.md).

# 3.5 Branches e merges

## 🌿Branches e Merges

Page description (optional)

🧠 **O que são branches?**

Pense num projeto como uma árvore.\
🌳 O **tronco principal** é o `main`.\
🌿 Os **galhos (branches)** são caminhos separados onde você pode testar ideias, corrigir bugs ou adicionar novas funcionalidades sem bagunçar o projeto principal.

***

### ✨ Por que usar branches?

* Testar sem medo de quebrar o projeto.
* Dividir tarefas entre pessoas da equipe.
* Trabalhar em várias ideias ao mesmo tempo.

***

### 🔀 Criando e usando branches

#### 1. Ver branches existentes:

```bash
git branch
```

#### 2. Criar uma nova branch:

```bash
git branch nome-da-branch
```

📦 Cria o galho, mas ainda **não troca para ele**.

> Exemplo:

```bash
git branch pagina-de-login
```

#### 3. Trocar para a nova branch:

```bash
git checkout nome-da-branch
```

> Exemplo:

```bash
git checkout pagina-de-login
```

🔄 Agora você está em outro galho. Pode mexer à vontade!

***

### ✍️ Trabalhando em uma branch

1. Faça modificações no projeto (ex: crie um arquivo `login.html`)
2. Adicione e faça commit:

```bash
git add .
git commit -m "Criei a página de login"
```

🔐 Essas mudanças ficam **somente nessa branch**.

***

### 📦 Voltando para o main

Depois de terminar sua ideia ou funcionalidade:

```bash
git checkout main
```

📌 Agora você voltou para o tronco principal da árvore (a branch `main`).

***

### 🔁 Unindo uma branch ao main (merge)

#### 1. Certifique-se que está no `main`

```bash
git checkout main
```

#### 2. Faça o merge:

```bash
git merge nome-da-branch
```

> Exemplo:

```bash
git merge pagina-de-login
```

🔗 Agora todas as mudanças da branch `pagina-de-login` foram adicionadas ao `main`.

***

### ⚠️ E se der conflito?

Conflitos acontecem quando dois arquivos foram modificados **na mesma linha** por branches diferentes.

👀 O Git vai te avisar:

> "Ei, edita esse arquivo manualmente e diz qual versão você quer manter!"

Depois de resolver:

```bash
git add nome-do-arquivo
git commit -m "Resolvi conflito de merge"
```

***

### 🧹 Dica de limpeza: apagar branch que já foi usada

Se a branch já foi mesclada e não será mais usada:

```bash
git branch -d nome-da-branch
```

> Exemplo:

```bash
git branch -d pagina-de-login
```

***

### 📚 Resumo Rápido dos Comandos

| Ação                | Comando                    |
| ------------------- | -------------------------- |
| Ver branches        | `git branch`               |
| Criar nova branch   | `git branch nome`          |
| Trocar de branch    | `git checkout nome`        |
| Criar e já trocar   | `git checkout -b nome`     |
| Voltar para o main  | `git checkout main`        |
| Unir branch ao main | `git merge nome-da-branch` |
| Apagar branch       | `git branch -d nome`       |

***

### 🧪 Exemplo Prático: Teste de Funcionalidade

1. Crie uma pasta `sistema-login`, inicie o Git:

   ```bash
   git init
   ```
2. Crie um `index.html`, adicione e faça commit:

   ```bash
   git add .
   git commit -m "Versão inicial"
   ```
3. Crie uma branch:

   ```bash
   git checkout -b login-page
   ```
4. Crie um arquivo `login.html` e adicione conteúdo básico.
5. Faça commit:

   ```bash
   git add .
   git commit -m "Criei página de login"
   ```
6. Volte para o main:

   ```bash
   git checkout main
   ```
7. Faça merge:

   ```bash
   git merge login-page
   ```
8. Veja que a página de login agora está dentro do `main` 🎉

***

📣 **Conclusão para quem tá começando:**

> Branch é como salvar rascunhos em outro caderno antes de escrever na versão final.\
> Merge é colar esse conteúdo de volta no caderno principal.

***


---

# 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://favelaware.gitbook.io/favelaware/3-git-e-github/3.5-branches-e-merges.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.
