Show diff of last commit
git diff HEAD~1
Delete a branch locally
git branch -d <branch>
Delete a branch from a remote
git push <remote> :<branch>
Moving commits from one branch to another
create the new branch to move the commits to
git checkout master
git checkout -b new_branch
this will copy the two most recent commits from old_branch to new_branch
git cherry-pick old_branch old_branch~1
Check out specific files from another branch or commit
git checkout <branch or commit hash> -- <path to file>
Check out a remote branch, creating a new local branch
git checkout --track <remote>/<branch>
Move hunks from unstaged to staged
git add -p
Move hunks from staged to unstaged
git reset -p
Reset unstaged hunks
git checkout -p
Initialize all submodules
git submodule update --init
Ignore changes to a tracked file
git update-index --assume-unchanged <file>
Start tracking changes again
git update-index --no-assume-unchanged <file>
Show all ignored files
git ls-files -v `git rev-parse --show-toplevel` | grep "^[a-z]"
Don't ride into it unless you know what you're doing!
Manipulate all commits that are 3 steps back from the current HEAD
git rebase -i HEAD~3
Delete a file permanently from your repository
git filter-branch --index-filter 'git rm --cached --ignore-unmatch <file to delete>' --prune-empty --tag-name-filter cat -- --all
Delete a folder recursively from your repository
git filter-branch --index-filter 'git rm -r --cached --ignore-unmatch <file to delete>' --prune-empty --tag-name-filter cat -- --all
[core]
editor = vim
excludesfile = ~/.gitignore_global
# This will cause Git to warn you about these kinds of whitespace.
whitespace = trailing-space,space-before-tab
# This activates colors in Git's command line output.
[color]
ui = true
# You can set whatever custom colors you like.
[color "branch"]
remote = magenta
[color "status"]
untracked = cyan
[alias]
m = checkout master
d = diff
f = fetch
co = checkout
cm = commit
st = status
stat = status
br = branch
bd = branch -d
up = fetch upstream
rb = rebase
pl = pull
pul = pull
psh = push
pshf = push --force
graph = log --graph --pretty=josh
graphall = !git graph --all
dif = diff
diif = diff
diffc = diff --cached
diffall = diff HEAD
diflog = log --oneline
difflog = log --oneline
branches = branch
remotes = remote -v
# Marks a file so that local changes will be ignored
forget = update-index --assume-unchanged
# Undoes what "git forget" does
remember = update-index --no-assume-unchanged
# This shows files affected by the "git forget" alias.
memories = !git ls-files -v `git rev-parse --show-toplevel` | grep "^[a-z]"
[push]
default = simple
# For Github's command line utility, hub
[hub]
protocol = ssh
[pretty]
# This sets up the colors and formatting for the "graph" alias
josh = %C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(bold white)— %an%C(reset)%C(bold yellow)%d%C(reset)
[apply]
# Git will automatically remove whitespace that it was configured to warn you about above.
whitespace = fix
golden..