GIT CHEAT SHEET

Local Changes

  • git status
  • --Change files in your working directory.

  • git add .
  • --Add all current changes to the next commit.

  • git commit -m "add commit"
  • --Commit previously staged changes.

Create

  • git clone
  • --Clone an existing repository.

  • git init
  • --Create a new local repository.

Update & Publish

  • git remote -v
  • --Clone an existing repository.

  • git remote add ~name~ ~url~
  • --Clone an existing repository.

  • git fetch ~remote~
  • --Clone an existing repository.

  • git pull
  • --Clone an existing repository.

  • git push
  • --Clone an existing repository.

Braches & Tags

  • git branch -av
  • --List all existing branches.

  • git checkout ~branch~
  • --Switch HEAD branch.

  • git branch ~name of branch~
  • --Create new branch based on your HEAD.

  • git branch -d
  • --Delete a local branch.

Merge & Rebase

  • git merge ~branch~
  • --Merge branch into current HEAD.

  • git add ~resolved-file~
  • --Solve conflicts and mark file as resolved.

  • git rm ~resolved-file~
  • --Solve conflicts and mark file as resolved.

Undo

  • git reset --hard HEAD
  • --Discard all local changes in working directory.

  • git checkout HEAD ~file~
  • --Discard local changes in a specific file.

  • git revert ~commit~
  • --Revert a commit.