-
Notifications
You must be signed in to change notification settings - Fork 107
Adiciona seção sobre GitHub e melhora consistência geral #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jadsonmorais
wants to merge
1
commit into
danielhe4rt:master
Choose a base branch
from
jadsonmorais:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Clone | ||
|
|
||
| Simplificado: _Baixar uma cópia completa de um repositório_ <br><br> | ||
| Até agora vimos o `git init`, que cria um repositório **novo e vazio**. Mas no dia a dia, o mais comum é você entrar em um projeto que **já existe** - seja no trabalho, em um projeto open source, ou em um repositório que você acabou de dar fork no GitHub. | ||
|
|
||
| Para isso usamos o comando **git clone**, passando a URL do repositório: | ||
|
|
||
| ```bash | ||
| git clone https://github.com/usuario/nome-do-repositorio.git | ||
| ``` | ||
|
|
||
| Isso vai: | ||
|
|
||
| 1. Criar uma pasta com o nome do repositório; | ||
| 2. Baixar todo o histórico de commits, branches e tags; | ||
| 3. Configurar automaticamente o repositório remoto chamado `origin`, apontando para a URL clonada (veremos mais sobre isso em [Remote](remote.md)). | ||
|
|
||
| Se quiser clonar em uma pasta com outro nome: | ||
|
|
||
| ```bash | ||
| git clone https://github.com/usuario/nome-do-repositorio.git meu-projeto | ||
| ``` | ||
|
|
||
| ## HTTPS vs SSH | ||
|
|
||
| Você vai notar que o GitHub oferece duas URLs para clonar: | ||
|
|
||
| ```bash | ||
| # HTTPS - pede usuário/token (ou abre o navegador) ao fazer push | ||
| git clone https://github.com/usuario/nome-do-repositorio.git | ||
|
|
||
| # SSH - usa uma chave configurada na sua máquina, sem pedir senha depois | ||
| git clone git@github.com:usuario/nome-do-repositorio.git | ||
| ``` | ||
|
|
||
| No começo, HTTPS costuma ser mais simples. Conforme você for fazer `push` com frequência, vale configurar uma chave SSH para não precisar autenticar a cada envio. | ||
|
|
||
| Ir para: [3.2. Config](config.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # .gitignore | ||
|
|
||
| Simplificado: _Lista de "não me siga"_ <br><br> | ||
| Todo projeto tem arquivos que **não devem** ir para o repositório: senhas, chaves de API, pastas de dependências (`node_modules`, `vendor`), arquivos de build, configurações pessoais do seu editor, logs, etc. | ||
|
|
||
| Se você rodar um `git add .` sem cuidado, todos esses arquivos entram no commit e acabam no histórico do projeto - inclusive em repositórios públicos no GitHub, o que pode expor senhas e chaves de acesso. | ||
|
|
||
| Para evitar isso, criamos um arquivo chamado **.gitignore** na raiz do projeto, listando o que o Git deve ignorar. | ||
|
|
||
| ``` | ||
| $ touch .gitignore | ||
| ``` | ||
|
|
||
| Dentro dele, cada linha representa um padrão de arquivo ou pasta a ser ignorado: | ||
|
|
||
| ```gitignore | ||
| # Dependências | ||
| node_modules/ | ||
| vendor/ | ||
|
|
||
| # Variáveis de ambiente e segredos | ||
| .env | ||
| .env.* | ||
| *.pem | ||
|
|
||
| # Build | ||
| dist/ | ||
| build/ | ||
|
|
||
| # Logs | ||
| *.log | ||
|
|
||
| # Configurações do editor/IDE | ||
| .vscode/ | ||
| .idea/ | ||
| ``` | ||
|
|
||
| ## Pontos importantes | ||
|
|
||
| - O `.gitignore` só funciona para arquivos **ainda não rastreados** pelo Git. Se um arquivo já foi commitado antes de entrar no `.gitignore`, ele continuará sendo monitorado - é necessário remover do controle de versão com: | ||
|
|
||
| ```bash | ||
| git rm --cached caminho/do/arquivo | ||
| ``` | ||
|
|
||
| - Existem modelos prontos de `.gitignore` para praticamente toda linguagem/framework no site [gitignore.io](https://www.toptal.com/developers/gitignore) ou no repositório oficial [github/gitignore](https://github.com/github/gitignore). | ||
| - **Nunca** suba arquivos `.env`, credenciais, tokens ou chaves privadas para o repositório, mesmo que ele seja privado. | ||
|
|
||
| Ir para: [3.5. Commit](commit.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # Pull | ||
|
|
||
| Simplificado: _Trazer as novidades do remote para o seu projeto local_ <br><br> | ||
| Enquanto você trabalha, seus colegas também estão commitando e fazendo `push` de alterações. O comando `git pull` serve para **atualizar sua branch local** com tudo que já foi enviado ao remote. | ||
|
|
||
| ```bash | ||
| git pull origin main | ||
| ``` | ||
|
|
||
| Na prática, `git pull` é a combinação de dois comandos que você já conhece: | ||
|
|
||
| ```bash | ||
| git fetch origin # baixa as novidades do remote (sem alterar seus arquivos) | ||
| git merge origin/main # mescla essas novidades na sua branch atual | ||
| ``` | ||
|
|
||
| Veja [Fetch](fetch.md) para entender melhor a primeira parte. | ||
|
|
||
| ## Quando rodar `git pull`? | ||
|
|
||
| - **Antes de começar a trabalhar**, para garantir que você está partindo do código mais atualizado; | ||
| - **Antes de criar uma branch nova**, para que ela já nasça a partir da versão mais recente da `main`; | ||
| - **Antes de dar `git push`**, caso o remote tenha recebido alterações novas desde a última vez que você sincronizou (veja [Push](push.md)). | ||
|
|
||
| ## Pull pode gerar conflitos | ||
|
|
||
| Como o `pull` faz um `merge` por debaixo dos panos, se você e um colega alteraram a **mesma linha do mesmo arquivo**, o Git vai pedir para você resolver o conflito manualmente antes de continuar. Isso é normal e faz parte do trabalho em equipe - veja o passo a passo em [Resolvendo conflitos](../5-github/resolvendo-conflitos.md). | ||
|
|
||
| ## git pull --rebase | ||
|
|
||
| Uma alternativa ao merge automático do `pull` é pedir para o Git **reaplicar seus commits locais por cima** das novidades baixadas, mantendo o histórico mais linear (sem um commit de merge extra): | ||
|
|
||
| ```bash | ||
| git pull --rebase origin main | ||
| ``` | ||
|
|
||
| Útil em times que preferem um histórico de commits mais "limpo", mas exige mais atenção ao resolver conflitos (veja [Rebase](rebase.md)). | ||
|
|
||
| Ir para: [3.15. Fetch](fetch.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # Push | ||
|
|
||
| Simplificado: _Enviar seus commits para o repositório remoto_ <br><br> | ||
| Tudo que você faz com `git commit` fica guardado **localmente**, na sua máquina. Para que seu time (ou o GitHub) veja essas alterações, você precisa **enviá-las** para o remote com o comando `git push`. | ||
|
|
||
| ```bash | ||
| git push origin main | ||
| ``` | ||
|
|
||
| Isso envia os commits da sua branch `main` local para a branch `main` do remote `origin`. | ||
|
|
||
| ## Primeiro push de uma branch nova | ||
|
|
||
| Quando você cria uma branch nova localmente (com `git switch -c minha-feature`) e faz commits nela, essa branch ainda **não existe** no remote. No primeiro push, use `-u` (ou `--set-upstream`) para vincular sua branch local à branch remota: | ||
|
|
||
| ```bash | ||
| git push -u origin minha-feature | ||
| ``` | ||
|
|
||
| A partir daí, basta `git push` (sem mais nada) que o Git já sabe para onde enviar. | ||
|
|
||
| ## Erros comuns | ||
|
|
||
| ### "rejected... (fetch first)" / "non-fast-forward" | ||
|
|
||
| ``` | ||
| ! [rejected] main -> main (fetch first) | ||
| error: failed to push some refs | ||
| ``` | ||
|
|
||
| Isso significa que o remote tem commits que você ainda não tem localmente (alguém do time fez push antes de você). A solução **não é forçar o push**, e sim trazer as alterações primeiro: | ||
|
|
||
| ```bash | ||
| git pull | ||
| # resolva eventuais conflitos (veja resolvendo-conflitos.md) | ||
| git push | ||
| ``` | ||
|
|
||
| ### Nunca use `git push --force` em branches compartilhadas | ||
|
|
||
| ```bash | ||
| git push --force origin main | ||
| ``` | ||
|
|
||
| Esse comando **sobrescreve o histórico remoto**, podendo apagar commits dos seus colegas sem aviso. Use apenas em branches pessoais (ex: sua própria branch de feature, antes de abrir o Pull Request) e, mesmo assim, prefira `git push --force-with-lease`, que falha caso alguém tenha enviado algo novo que você ainda não viu. | ||
|
|
||
| Ir para: [3.14. Pull](pull.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # Remote | ||
|
|
||
| Simplificado: _O "endereço" do repositório na nuvem_ <br><br> | ||
| Tudo que vimos até agora aconteceu **apenas na sua máquina**. Mas o Git é um sistema distribuído: o mesmo repositório pode existir em vários lugares - na sua máquina, na do seu colega, e em um servidor compartilhado como GitHub, GitLab ou Bitbucket. | ||
|
|
||
| Um **remote** é justamente uma referência para uma dessas outras cópias do repositório. Quando você clona um projeto (veja [Clone](clone.md)), o Git já cria automaticamente um remote chamado `origin`, apontando para a URL de onde você clonou. | ||
|
|
||
| ## Listando os remotes configurados | ||
|
|
||
| ```bash | ||
| $ git remote -v | ||
| origin https://github.com/usuario/nome-do-repositorio.git (fetch) | ||
| origin https://github.com/usuario/nome-do-repositorio.git (push) | ||
| ``` | ||
|
|
||
| ## Adicionando um novo remote | ||
|
|
||
| Útil quando você criou o repositório localmente com `git init` e agora quer conectá-lo a um repositório vazio criado no GitHub: | ||
|
|
||
| ```bash | ||
| git remote add origin https://github.com/usuario/nome-do-repositorio.git | ||
| ``` | ||
|
|
||
| ## Trabalhando com forks: origin vs upstream | ||
|
|
||
| Uma situação muito comum em times e em projetos open source: você faz um **fork** (sua cópia) de um repositório, clona o **seu fork**, mas também precisa acompanhar as atualizações do repositório **original**. Para isso, é comum adicionar um segundo remote chamado `upstream`: | ||
|
|
||
| ```bash | ||
| $ git remote -v | ||
| origin https://github.com/seu-usuario/projeto.git (fetch) | ||
| origin https://github.com/seu-usuario/projeto.git (push) | ||
|
|
||
| $ git remote add upstream https://github.com/dono-original/projeto.git | ||
| $ git remote -v | ||
| origin https://github.com/seu-usuario/projeto.git (fetch) | ||
| origin https://github.com/seu-usuario/projeto.git (push) | ||
| upstream https://github.com/dono-original/projeto.git (fetch) | ||
| upstream https://github.com/dono-original/projeto.git (push) | ||
| ``` | ||
|
|
||
| Assim você pode usar `git fetch upstream` / `git merge upstream/main` para trazer as novidades do projeto original para o seu fork, sem perder a referência de onde enviar (`push`) as suas próprias alterações (`origin`). Esse fluxo é detalhado em [Fork e Pull Request](../5-github/fork-e-pull-request.md). | ||
|
|
||
| ## Removendo ou renomeando um remote | ||
|
|
||
| ```bash | ||
| git remote remove upstream | ||
| git remote rename origin upstream | ||
| ``` | ||
|
|
||
| Ir para: [3.13. Push](push.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Systematic off-by-one error in section numbering across command navigation links.
All five navigation link updates reference section numbers that are one less than their position in the README roadmap. The root cause is treating the README's 1-based item counting (items 1–19) as if Repositório itself is "3.1", when it should be: Repositório=3.1, Clone=3.2, etc.
3-comandos/repositorio.md#L16-L16: Change "3.1.1. Clone" → "3.2. Clone" and "3.2. Config" → "3.3. Config"3-comandos/config.md#L20-L20: Change "3.3. .gitignore" → "3.4. .gitignore"3-comandos/reset.md#L23-L23: Change "3.12. Remote" → "3.13. Remote"3-comandos/log.md#L51-L51: Change "3.17. Stash" → "3.18. Stash"3-comandos/stash.md#L142-L142: Change "3.18. Cherry-pick" → "3.19. Cherry-pick"📍 Affects 5 files
3-comandos/repositorio.md#L16-L16(this comment)3-comandos/config.md#L20-L203-comandos/reset.md#L23-L233-comandos/log.md#L51-L513-comandos/stash.md#L142-L142🤖 Prompt for AI Agents