Skip to content

Instantly share code, notes, and snippets.

@raineorshine
Created April 1, 2014 22:53
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
  • Save raineorshine/9924743 to your computer and use it in GitHub Desktop.
Save raineorshine/9924743 to your computer and use it in GitHub Desktop.
Git Cheat Sheet: Just the Essentials (13 Commands). See https://gist.github.com/5128563 for more.
# Status Commands - These are always safe to execute and don't change the repo.
git status # Print the status of the current repo
git log # Print a list of the most recent commits
git diff # Show all differences between unstaged changes
# and the last commit.
git remote -v # Show all remotes with name and url.
# Repo Commands - These modify the state of the repo in some way but do not modify files
git init # Initialize a new repo in the current folder
git add MYFILE # Add a file with changes to the staging area to be committed.
git add -A # Add all added, removed, or changed files to the staging area.
git reset MYFILE # Unstage a file (does not modify the file)
git commit -m "Added x,y,z" # Commit the staged files to the version history.
git remote add name MYURL # Add a remote with the given name
# Modification Commands - These modify local files.
git checkout . # Delete all local changes and restore the last commit.
git clone MYURL # Download a remote repo into a folder of the same
# name. Automatically creates a remote called origin.
git clone MYURL foldername # Same as above but give the folder a custom name.
# Sync Commands - These may modify local and remote files.
git push origin master # Push all changes to the local 'master' branch
# to the remote named 'origin'
git pull origin master # Pull all changes from the remote 'origin' branch
# to the local branch 'master'.
git push -u origin master # Same as above but sets 'upstream tracking' to the
# given branch and remote to enable simple 'git push'
git push # Push to the tracked branch after the push -u command.
git pull # Pull from the tracked branch after the push -u command.
@subtleazn
Copy link

Thanks for this~!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment