Skip to content

Instantly share code, notes, and snippets.

@ahcode0919
Last active May 14, 2020 07:14
Show Gist options
  • Save ahcode0919/1b33c90bc6b3a7143399dfa50aae6935 to your computer and use it in GitHub Desktop.
Save ahcode0919/1b33c90bc6b3a7143399dfa50aae6935 to your computer and use it in GitHub Desktop.
Common Git Commands

Git Cheatsheet

Global

  • Create origin branch when creating branch git config --global branch.autosetupmerge always
  • Add ssh key to keychain to eliminate retyping in password ssh-add -K ~/.ssh/id_rsa

Add files

  • Add All Files - git add .

Amend Commit

  • Add new changes - git commit --amend
  • Change commit author - git commit --amend --author="John Doe <jdoe@test.com>"

Branches

  • Create and checkout branch - git checkout -b {branch_name}
  • Create branch - git branch {branch_name}
  • Delete branch - git branch -D {branch_name}
  • List branches - git branch --list

Fetch

  • Fetch latest - git fetch

Investigation

  • file commit log - git log {current path to file} - git log src/compenents/some.js

Push

  • Push: git push
  • Push Origin: git push -u origin {branch-name}
  • Force Push: git push -f

Rebase

  • Interactive Rebase on to same branch: git rebase -i
  • Rebase on to different branch: git rebase -i {branch}
  • Rebase the top X commits: git rebase -i {branch} HEAD~X

Reset

  • Reset commit (keep changes): git reset --soft HEAD~{number of commits}
  • Reset commit (delete changes): git reset --hard HEAD~{number of commits}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment