Skip to content

Instantly share code, notes, and snippets.

@pauldonnelly
Created October 24, 2014 11:11
Show Gist options
  • Save pauldonnelly/6a536826bef3e4355f7d to your computer and use it in GitHub Desktop.
Save pauldonnelly/6a536826bef3e4355f7d to your computer and use it in GitHub Desktop.
GIT Commands Cheat Sheet
=== Basic Commands ===
git status
checks the status of your files
git add
multipurpose command; allows you to track files, stage files, and mark merge conflicted files as resolved
git diff
compares working directory to staging area
git diff --cached
compares staged changes to last commit
git commit –m "message"
commits everything in your staging area, uses inline commit message
git commit –a –m "message"
automatically stages every currently tracked file and commits them (allows you to skip “git add” command)
git rm [filename]
untracks the file and removes it from your working directory
git rm --cached [filename]
untracks the file, but keeps it in your working directory - useful if you forgot to include certain files
in your .gitignore
git mv [orig_name] [new_name]
changes the file's name
git log
shows the commit history in reverse chronological order (i.e. most recent first)
=== "Undoing Things" Commands ===
git commit --amend overrides
your most recent commit - i.e. it "undoes" your most recent with what's currently in your staging area
git reset HEAD [filename]
allows you to unstage a particular file; this file returns back to the modified state
git checkout -- [filename]
allows you to discard any changes you've made to the file since the last commit Note: use this command carefully - the discarded changes cannot be recovered
=== Remote Repository Commmands ===
git pull [remote-name] [branch-name]
automatically fetches data from the remote server (typically called "origin") and attempts to merge it into the code you're working on; branch-name is typically "master" if you haven't created your own branch
git push [remote-name] [branch-name]
pushes your code from the branch you're on (typically "master" if you haven't created your own branch) upstream to the remote server (typically called "origin")
=== Merging and Branching Commands ===
git merge [branch-name]
merges the specified branch with the current working directory
git branch
view all available branches
git branch [branch-name]
create a new branch
git checkout [branch-name]
set current working directory to branch-name
git checkout -b [branch-name]
create a new branch and set current working directory to it
git merge [branch-name]
merge branch-name into the current branch
git branch -d [branch-name]
deletes the specified branch
=== Changing to Previous Commits Commands ===
git revert <prev_commit>
creates a new commit with a reverse patch that cancels out everything after that previous commit
git checkout -b <branchname> <prev_commit>
allows you to return to a previous commit and create a branch using it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment