Skip to content

Instantly share code, notes, and snippets.

@robcthegeek
Created June 7, 2010 09:35
Show Gist options
  • Save robcthegeek/428461 to your computer and use it in GitHub Desktop.
Save robcthegeek/428461 to your computer and use it in GitHub Desktop.
Handy Git Commands for Quick Reference
# Edit Global .gitconfig, Adding/Updating the Following Section
[alias]
s = status -su
d = difftool
c = commit -am
co = checkout
l = log --pretty=oneline -20
log-del = log --diff-filter=D --
b = branch
r = reset --hard
ru = remote update
cln = clean -df
p = !git pull & git push
a = add
# List ALL Branches (Including Remote Tracking Branches)
$ git branch -a
# Pull from an Upstream Branch
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/{branch}
$ git checkout -b {branch} origin/{branch}
# Note the use of the remote name ("origin") as well as branch name ("branch") since you can have more than one remote..
# ... If you don't have Tracking on local branch...
git branch --set-upstream foo upstream/foo
# Delete Local Branches That Have Been Deleted on Remote
$ git remote prune {remote}
# Delete a Remote Branch
$ git push {remote} :{branch}
# Note the left argument of the "sourceBranch" is missing (normally "git push {remote} {source}:{target}
# In effect, we are saying "push nothing to remote branch 'x'".
# Diff Two Branches (Files Only)
$ git diff --name-status branchA..branchB
# Branching Config
# Tell Git to Auto-Track the Branch that you are branching FROM:
git config branch.autosetupmerge true
# Tell Git to REBASE from Tracking Branch Rather than Pull (Merge)
git config branch.autosetuprebase true
# Add an Existing Local Repo to Remote
$ git remote add origin git://gitUrl
# Bind Branch (Master) to Remote & Add Tracking
$ git config branch.master.remote origin
$ git config branch.master.merge refs/heads/master
# Setup Push/Pull Defaults
git config --global push.default matching
# Save Current Changes to Working Directory and Revert to HEAD.
$ git stash "Message"
# List Current Stash Stack
$ git stash list
stash@{0}: The Message I Stashed With
# Apply Changes from Stash, Removing from Stash ("apply" Can Be Used to Preserve Stash)
$ git stash pop
$ git stash pop stash@{indexInList}
# Clear All Stashed Items (Caution!)
$ git stash clear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment