#Git Commands I Love
##Reset & Clean
git reset HEAD --hard
A hard reset may leave files behind which are now untracked because of a removal.
To check whether anything needs cleaning up do a trial clean like so:
git clean -d -n
If you have things that will be removed, you should then see a message like this:
Would remove path/to/something
To clean these files up, try:
git clean -d -f
You should then see the following output:
Removing path/to/something
##Show
####Copy a file from a specific branch
git show branch_name:package.json > ~/Desktop/package.json
##Diff
###Diff N'th Last Commit Generate a diff between current head and the nth' last commit.
git diff @{1}..
###Show Diff Specific File in
git show c9714e6dff8e39a96027b0bafcf0909d2f3493aa:source/js/something.js | sublime
###Using DiffTool & MergeTool
git mergetool
git difftool
###The Diff between 2 commits using difftool
git difftool 08bfe60 9ae5317
##Conflicts
###List Conflicted Files
git ls-files -u
##Branches
###Delete Local Branch
git branch -d the_local_branch
###Delete Remote Branch
git push origin -delete the_remote_branch
###Checkout while creating new branch
git checkout -b awesomenewbranchname
###Pushing Between Remote Branches
git push origin x-branch1:x-branch2
##Patches
###Create a Patch
git format-patch master --stdout > something.patch
###Apply a Patch
git apply --stat something.patch
###Patching from a Diff
patch -p1 < ~/Desktop/patch-name.diff
##Stashing
####Listing Stashes
git stash list
###Apply N'th Stash
git stash apply stash@{0}
##Blame
###Who touched that line?
git log -S "function itsYourLuckyDay() {" -- source/js/some-module.js
##Graph/Info
###Command Line Commit Graph
git log --graph --pretty=oneline --abbrev-commit --decorate --color
##Configuration
###My Git Config
[user]
name = Alistair MacDonald
email = amacdonald@somecompany.com
[credential]
helper = osxkeychain
[core]
excludesfile = /Users/[user]/.gitignore_global
editor = sublime
pager = tig
[color]
ui = true
diff = false
[difftool "Kaleidoscope"]
cmd = ksdiff --partial-changeset --relative-path \"$MERGED\" -- \"$LOCAL\" \"$REMOTE\"
[diff]
tool = Kaleidoscope
[difftool]
prompt = false
[mergetool "Kaleidoscope"]
cmd = ksdiff --merge --output \"$MERGED\" --base \"$BASE\" -- \"$LOCAL\" --snapshot \"$REMOTE\" --snapshot
trustExitCode = true
[mergetool]
prompt = false
[merge]
tool = Kaleidoscope
###Kaleidoscope Config
[difftool "Kaleidoscope"]
cmd = ksdiff --partial-changeset --relative-path \"$MERGED\" -- \"$LOCAL\" \"$REMOTE\"
[diff]
tool = Kaleidoscope
[difftool]
prompt = false
[mergetool "Kaleidoscope"]
cmd = ksdiff --merge --output \"$MERGED\" --base \"$BASE\" -- \"$LOCAL\" --snapshot \"$REMOTE\" --snapshot
trustExitCode = true
[mergetool]
prompt = false
[merge]
tool = Kaleidoscope
###Setup Editor & Pager
Usually VIM is used as a diff pager. I am using TIG, installed with Brew.
// For...
git config --global core.editor sublime
// For diff, etc
git config --global core.pager tig
// Colorful GIT output in the UI
git config --global color.ui true
// ... but not when piped to TIG
git config --global color.diff false