Git Cheatsheet

It’s small, fast, and github is rad. So I am trying to learn it.

# Setup
git config --global --list
git config --global user.name "Ken-ichi"
git config --global user.email "fortinbras@norway.net"
 
# The colors, children.  Mm-hey
git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto
 
# Getting Info
git remote -v # Display the remote repository URL
git log # duh
git show COMMIT # equivalent of svn log -r REV_NUM, but with diffs
 
# Committing
git add .
git commit -a
 
# Amending
git commit -a --amend
 
# Reverting
git reset --hard HEAD # revert everything to HEAD
git checkout path/to/file # reset a single file
 
# Stashing
git stash # stash changes on this branch so you can switch and work on something else
git stash pop # bring back the stashed changes
 
# Pushing to another repos
# could be local like /path/to/somewhere 
# or ssh://me@there.net/path/to/repos
git push path/to/repos
 
# Branching and merging
git branch new_branch && git checkout new_branch # make a new branch and switch to it
git checkout -b new_branch # same as above
git merge other_branch
git mergetool -t opendiff # resolve conflicts in a merge with FileMerge

Leave a Reply