Skip to content

Latest commit

 

History

History
169 lines (163 loc) · 3.24 KB

git.md

File metadata and controls

169 lines (163 loc) · 3.24 KB

Git commands

General

  • List config
    git config --list
  • Set config
    git config --global user.name "Fulano de Tal"
    git config --global user.email [email protected]
  • Adding files to stage
    git add file.txt
  • Adding part of the file
    git add -p
  • Commiting
    git commit -m "Lorem ipsum"
  • Fixing commit message
    git commit -m "Lorem ipsum dolor sit amet" --amend
  • Upload
    git push origin branch-name
  • Checking branch status
    git status
  • Download commits from remote branch
    git pull origin branch-name
  • Using tool to merge branches
    git mergetool
  • Remove the file from the Git repository and the filesystem
    git rm file.txt
  • Remove the file only from the Git repository and not remove it from the filesystem
    git rm --cached file.txt
  • Undo commits, but does not touch the index file or the working tree at all
    git reset --soft branch-name
    git reset --soft HEAD~
  • Undo commits permanently and also throw away any uncommitted changes
    git reset --hard branch-name
    git reset --hard HEAD~
  • Undo the most recent local commits while leaving your working tree (the state of your files on disk) untouched
    git reset HEAD~1
  • Untrack a file that has been committed
    git rm -r --cached file-name

Logs

  • Checking commit logs
    git log
  • Checking operation logs
    git reflog
  • Checking logs of specific file
    git log -p file-name
    git log --graph --oneline --all

Branch

  • changing branches
    git checkout nome_branch
  • show branches
    git branch
  • create a branch
    git branch nome_branch
  • create a branch off from the main branch
    git checkout -b nome_branch main
  • show all branches
    git branch -a
  • show remote branches
    git branch -r

Stash

  • save modified and staged changes
    git stash
  • list stack-order of stashed file changes
    git stash list
  • write working from the top of the stash stack
    git stash pop
  • discard the changes from the top od the stash stack
    git stash drop

Diff

  • show alterations to be sent
    git diff --stat
  • show alterations in current branch of what is changed but not staged
    git diff
  • show alterations in current branch of what is staged but not yet commited
    git diff --staged
  • show alterations between files in current branch and remote
    git diff -p file-name
  • show alterations between files in current branch and remote specifying a commit
    git diff -p file-name f90b0dd3949..70ad8038d0

Repository

  • show repository url
    git remote -v
  • altering repository url
    git remote set-url origin ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/foo
  • upload a existent repository
    git push ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/foo --all