Skip to content

Instantly share code, notes, and snippets.

@fuzzylimes
Last active July 15, 2018 19:02
Show Gist options
  • Save fuzzylimes/ac511e6f0afb804e5e0cda5fae68b616 to your computer and use it in GitHub Desktop.
Save fuzzylimes/ac511e6f0afb804e5e0cda5fae68b616 to your computer and use it in GitHub Desktop.
Git commands that I always forget...

Basic stuff

  • git init will create an empty git repo
  • Git does not store multiple versions of the code
  • Initial commit will create the master branch

git log

  • Shows the git commit history
  • HEAD will follow the latest commit

Checkout to specific commit

  • git checkout <commitId>
  • Can't add/commit after checked out. Commit does not match branch

Switch back to master

git master git checkout master

Jumping back to Commit

  • git reset --hard <commitID>

Backout unsaved chnages

  • git checkout -- <filename>

Display all branches

  • git branch

Creating new branch

  • git checkout -b <branch_name>
  • Sets HEAD against new branch and master

Merge back to master

  • Change back to master branch first
  • git merge <branch_name>

Deleting a branch

  • git branch -D <branch_name>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment