Skip to content

Instantly share code, notes, and snippets.

@jonfk
Last active September 19, 2016 18:08
Show Gist options
  • Save jonfk/9e4787ffa867e16b81f5 to your computer and use it in GitHub Desktop.
Save jonfk/9e4787ffa867e16b81f5 to your computer and use it in GitHub Desktop.
git_cheatsheet

Git Cheatsheet

Git Branches

  • view all branches including remote

    git branch -a
    # may require git fetch to view other remotes
    git fetch jonfk
  • fetch a remote branch

    git checkout --track origin/remote_branch_name
    # or create new branch tracking remote branch
    git checkout -b remote-branch-name origin/remote-branch-name
  • checking out a new branch

    git checkout -b new_branch_name
  • deleting a remote branch

    git push origin --delete <branchName>
  • deleting a local branch

    git branch -D <branchName>

Git Undos

  • Undo git add

    git reset
  • Undo git commit

    git reset --soft HEAD~1
  • Discard all uncommitted work

    git checkout -- .
    # or
    git reset --hard
  • Remove all untracked files and directories

    git clean -fd

git submodules

  • add submodule

    git submodule add https://github.com/<user>/rock rock
    # or
    git submodule add [email protected]:<user>/rock rock
  • Download the contents of submodules

    git submodule update --init --recursive
  • Clone repository and download submodules

    git clone --recursive <project url>

Git remotes

  • Update remote url

    git remote set-url origin https://github.com/<user>/rubber-band

git tags

  • Remove remote tag 12345

    git tag -d 12345
    git push origin :refs/tags/12345

Misc Config

  • Enable autocorrect after half a second

    git config --global help.autocorrect 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment