Created
June 7, 2010 09:35
-
-
Save robcthegeek/428461 to your computer and use it in GitHub Desktop.
Handy Git Commands for Quick Reference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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