Skip to content

Instantly share code, notes, and snippets.

@AlexGalhardo
Created May 6, 2022 18:35
Show Gist options
  • Save AlexGalhardo/c07a8a994a342c9973812b10a38ffdbe to your computer and use it in GitHub Desktop.
Save AlexGalhardo/c07a8a994a342c9973812b10a38ffdbe to your computer and use it in GitHub Desktop.

Revisions

  1. AlexGalhardo created this gist May 6, 2022.
    120 changes: 120 additions & 0 deletions GIT-COMMANDS.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,120 @@
    ## Install Git
    - sudo apt install -y git

    ## Edit Password
    - https://stackoverflow.com/questions/68775869/support-for-password-authentication-was-removed-please-use-a-personal-access-to
    - git config --global user.name "alexgalhardo"
    - git config --global user.email "[email protected]"
    - git config --global credential.helper cache
    - git config --global --unset credential.helper

    ## Iniciar git dentro do repositório
    - git init

    ## Adicionar arquivo para o stage
    - echo "Hello He4rt Devs" > index.html
    - git add ola.txt

    ## Adicionar todos os arquivos para o stage
    - git add .

    ## Fazer commit com comentário
    - git commit -m 'comentario_here'

    ## Criar Branch development
    - git checkout -b development
    - git branch

    ## Merge branch development to master
    - git checkout master
    - git merge development

    ## Adicionar local remoto
    - git remote add github url_github_here

    ## Push branch master para local remoto
    - git push github master

    ## Pegar arquivos(pull) da branch master do local remoto
    - git pull github master

    ## Ver todos os logs dos commits
    - git log

    ## Ver todas as alteraões feitas em cada commit
    - git show

    ## Push outra branch para local remoto
    - git push github dev

    ## Ver alterações feitas antes do git add
    - git diff

    ## Deletar .git local
    - rm -rf .git

    ## Apagar Diretório Remoto
    - git remote rm diretorio

    ## Apagar arquivo ola.txt do git stage
    - git rm ola.txt -f

    ## Apagar todos os arquivos dentro de um diretório forçado e de forma recursiva
    - git rm nome_pasta/. -fr

    ## Apagar branch locamente
    - git branch -D <nome do branch>

    ## Apagar branch remoto
    - git push <nome do origin> <nome do branch> --delete

    ## Evitar de algum arquivo não ser visto pelo git
    - criar arquivo chamado ".gitignore" (adicionar arquivos que não serão vistos pelo git dentro deste arquivo)

    ## GIT Fetch All Branchs
    - https://stackoverflow.com/questions/10312521/how-to-fetch-all-git-branches
    - git fetch --all

    ## GIT Pull All Branchs
    - git pull --all

    ## GIT Push All Branchs To All Remotes
    - https://stackoverflow.com/questions/5785549/able-to-push-to-all-git-remotes-with-the-one-command
    - git remote | xargs -L1 git push --all
    - git remote | xargs -L1 -I R git push R master (push master)

    ## Revert to GIT Hash
    - git revert a867b4af..0766c053

    ## GIT Clear History
    - rm -rf .git
    - git init
    - git add .
    - git commit -m "Initial commit"
    - git remote add origin [email protected]:<YOUR ACCOUNT>/<YOUR REPOS>.git
    - git push -u --force origin master

    ## Uninstall GIT
    - apt-get remove git
    - apt-get remove --auto-remove git
    - apt-get purge git
    - apt-get purge --auto-remove git

    ## Remove Remote Origin
    - https://stackoverflow.com/questions/16330404/how-to-remove-remote-origin-from-a-git-repository
    - git remote set-url origin git://new.url.here
    - git remote remove origin

    ## Merge Branch
    - git checkout -v new-branch
    - git add .
    - git commit –m "Some commit message"
    - git checkout master
    - git merge new-branch

    ## Rename Remote
    - git remote rename origin github
    - git push --all origin

    - git branch -d localBranchName
    - git push origin --delete remoteBranchName