Commands I (Basic)

Comandos Git básicos para controle de versão.

Comandos Git Básicos

Comandos essenciais para começar a usar Git no seu dia a dia.

Configuração Inicial

Configure seu nome e email antes de começar a usar Git.

Definir seu nome:

bash
git config --global user.name "Seu Nome"

Definir seu email:

bash
git config --global user.email "seu@email.com"

Ver todas as configurações:

bash
git config --list

Criar e Clonar Repositórios

Inicie um novo repositório ou clone um existente.

Inicializar repositório local:

bash
git init

Clonar repositório remoto:

bash
git clone https://github.com/usuario/repo.git

Status e Mudanças

Verifique o estado do seu repositório e veja mudanças.

Ver status dos arquivos:

bash
git status

Ver diferenças não staged:

bash
git diff

Ver diferenças staged:

bash
git diff --staged

Adicionar e Commitar

Adicione arquivos ao staging e crie commits.

Adicionar arquivo específico:

bash
git add arquivo.js

Adicionar todos os arquivos:

bash
git add .

Adicionar interativamente:

bash
git add -p

Criar commit com mensagem:

bash
git commit -m "feat: adiciona nova funcionalidade"

Add e commit em um comando:

bash
git commit -am "fix: corrige bug"

Branches Básicas

Crie e navegue entre branches.

Listar branches:

bash
git branch

Criar nova branch:

bash
git branch feature/nova-funcionalidade

Mudar para outra branch:

bash
git checkout feature/nova-funcionalidade

Criar e mudar para branch (atalho):

bash
git checkout -b feature/nova-funcionalidade

Comando moderno para mudar branch:

bash
git switch feature/nova-funcionalidade

Sincronizar com Remoto

Envie e receba mudanças do repositório remoto.

Ver repositórios remotos:

bash
git remote -v

Adicionar repositório remoto:

bash
git remote add origin https://github.com/usuario/repo.git

Baixar mudanças do remoto:

bash
git pull origin main

Enviar commits para remoto:

bash
git push origin main

Enviar e definir upstream:

bash
git push -u origin feature/nova-funcionalidade

Histórico de Commits

Visualize o histórico de commits do projeto.

Ver histórico completo:

bash
git log

Histórico resumido (uma linha por commit):

bash
git log --oneline

Histórico com gráfico de branches:

bash
git log --graph --oneline --all