> 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-9/interagindo-com-o-repositorio-remoto-hello-world/alterando-hello-world-localmente/salvando-alteracoes-no-controle-de-versao-local.md).

# Salvando Alterações no Controle de Versão Local

Agora, vamos ver o processo completo de como salvar alterações no seu repositório Git local a partir de um novo branch. A prática de utilizar branches específicos para tarefas e correções ajuda a manter o fluxo de trabalho organizado e facilita a integração das modificações ao projeto principal.

## Passo a Passo

### Verificar estado atual do repositório

Antes de realizar qualquer modificação, é importante verificar o estado atual do repositório.

```bash
git status
▶ On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")
```

O estado atual do README.md é ***tracked*** e ***modified**, u*ma vez que o arquivo foi modificado anteriormente com a adição do GIF de boas vindas.

### Criar um novo branch

Uma boa prática, especialmente para iniciantes, é evitar modificar diretamente o branch principal (`main`). Para cada nova tarefa ou correção, é recomendável criar um branch específico. Essa abordagem é conhecida como **feature branch**, onde cada funcionalidade ou correção é desenvolvida separadamente antes de ser integrada ao projeto principal.

Crie um novo branch chamado `issue-1` e alterne para ele.

```bash
git switch -C issue-1
▶ Switched to a new branch 'issue-1'
```

### Verificar estado atual do repositório

Ao verificar o estado do repositório, agora a primeira linha retornada deve ser `On branch issue-1` ao a invés de `On branch main`.

```bash
git status
▶ On branch issue-1
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")
```

O estado atual do README.md permanece ***tracked*** e ***modified**.*

### Adicionar README.md

Agora, adicione o arquivo ao **staging area**, preparando-o para o commit.

```bash
git add README.md
```

### Verificar estado atual do repositório

Verifique novamente o estado do repositório.

```bash
git status
▶ On branch issue-1
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	modified:   README.md
```

O estado do README.md agora é **tracked e staged**.

### Git commit

Agora, salve as alterações no histórico do Git com um commit.

```bash
git commit -m 'Adicionando GIF de boas vindas ao README.md'
▶ [issue-1 29f1d56] Adicionando GIF de boas vindas ao README.md
 1 file changed, 2 insertions(+)
```

### Verificando o log do repositório

Para confirmar que o commit foi registrado corretamente, utilize o comando:

```bash
git log
```

Saída esperada (algo como):

```bash
commit 2d942e747a89210df6d1454045abaa3ab451bda6 (HEAD -> issue-1)
Author: aprendizCumbucaDev <aprendiz.cumbucadev@gmail.com>
Date:   Mon Mar 10 20:57:46 2025 -0300

    Adicionando GIF de boas vindas ao README.md

commit 2e0d77fa56b7dc2b9c830c92d132143eacadcdf0 (origin/main, origin/HEAD, main)
Author: aprendizCumbucaDev <aprendiz.cumbucadev@gmail.com>
Date:   Mon Jan 20 14:44:57 2025 -0300

    Atualizando o README.md

    Adicionando o objetivo do repositório.

commit e140d961188e52636238ea60df81bc56f065a9ed
Author: aprendizCumbucaDev <aprendiz.cumbucadev@gmail.com>
Date:   Thu Jan 9 16:58:20 2025 -0300

    Initial commit

```

Note que o seu último commit aparece apenas no branch `issue-1`, indicado por `(HEAD -> issue-1)`. Isso significa que seu novo commit está apenas no branch `issue-1`, enquanto o branch `main` local ainda está alinhado com o repositório remoto.&#x20;

{% hint style="success" %}
Quer comprovar na prática?

* Mude de volta para o branch main com <mark style="color:purple;">git</mark> <mark style="color:orange;">switch</mark> <mark style="color:green;">main</mark>.
* Confira o log com <mark style="color:purple;">git</mark> <mark style="color:orange;">log</mark>.
* Você verá que o commit mais recente ainda **não está no `main`**, apenas no `issue-1`
* Retorne ao branch `issue-1` com <mark style="color:purple;">git</mark> <mark style="color:orange;">switch</mark> <mark style="color:green;">issue-1</mark> para continuar de onde paramos.
  {% endhint %}

***

Após salvar suas alterações no controle de versão local, o próximo passo é enviá-las para o repositório remoto, o que abordaremos a seguir.


---

# 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-9/interagindo-com-o-repositorio-remoto-hello-world/alterando-hello-world-localmente/salvando-alteracoes-no-controle-de-versao-local.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.
