Skip to content

Instantly share code, notes, and snippets.

@tiagobbraga
Last active February 19, 2025 15:12
Show Gist options
  • Save tiagobbraga/84d2f5a43774e0297b4506aa1496e515 to your computer and use it in GitHub Desktop.
Save tiagobbraga/84d2f5a43774e0297b4506aa1496e515 to your computer and use it in GitHub Desktop.
git-commands
Git clone com específico branch:
$ git clone --branch <branchname> <remote-repo-url>
Remover todos os commits
$ git checkout --orphan latest_branch
$ git add -A
$ git commit -am "mensagem"
$ git branch -D main
$ git branch -m main
$ git push -f origin main
Remover um arquivo específico
$ git rm --cached <filename>
Remover todos os arquivos gitignore
$ git rm -r --cached .
$ git add .
$ git commit -m "MESSAGE"
Remover arquivo do commit e remover o arquivo do histórico
$ git rm --cached PATH_FILE
// Não esqueça de adicionar o arquivo no .gitignore
$ git filter-branch --force --index-filter 'git rm --cache --ignore-unmatch PATH_FILE' --prune-empty --tag-name-filter cat -- --all
$ git push --force origin BRANCH_NAME
Novo branch com untracked files
$ git add -A
$ git stash
$ git checkout <branch>
$ git stash pop
Trocar url remote
$ git remote set-url origin <new_url_remote>
Criar tag
$ git tag -a v1.0 -m "MESSAGE"
Deletar tag local
$ git tag -d <tag_name>
Deletar tag remota
$ git push --delete origin <tag_name>
Compartilhar tag
$ git push origin v1.0
Renomear tag
$ git tag new old
$ git tag -d old
$ git push origin new :old
Commit sem criar nova mensagem (Necessário --force ao fazer push)
$ git commit -C HEAD --amend
Rollback para um determinado commit
$ git checkout 0d1d7fc32
Caso queira um rollback para um determinado commit para um novo branch
$ git checkout -b <NAME_BRANCH> 0d1d7fc32
Branch temporário (sem histórico de commit(s))
$ git checkout --orphan temp_branch
$ git branch -A
$ git commit -m "Inicial commit"
$ git branch -D main # deleta o branch principal (se esse for o nome)
$ git branch -m main # renomeia o branch temporário
$ git push origin main --force # usando force para caso o branch main remotamente tenha commits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment