git Cheat Sheet
always pull from the same
git config branch.master.remote origin
git config branch.master.merge refs/heads/master
Start from existing code (-u is to always push to the same)
git remote add origin git@github.com:trufa/test.git
git push -u origin master
Use kdiff3 as mergetool to solve conflicts
(paste this inside of your .git/config file)
[merge]
tool = kdiff3
[mergetool "kdiff3"]
path = C:/Program Files/KDiff3/kdiff3.exe
keepBackup = false
trustExitCode = false
Four ways of undoing last n commits
You want to nuke commit your and never see it again (Careful! Permanent loss).
git reset --hard HEAD~n
You want to undo the commit but keep your changes
git reset HEAD~n
Undo your commit but leave your files and your index:
git reset --soft HEAD~n
If you only want to change the last commit message
git commit --amend -m "New commit message"
Basic branching (tutorial)
Checkout to a new branch
git checkout -b newBranchName
Go back and merge
git checkout master
git merge newBranchName
Revert uncommited file to last version
git checkout filename
Set vimdiff as default difftool (source)
git config --global diff.tool vimdiff
git config --global difftool.prompt false
git config --global alias.d difftool
Stash local changes to be able to pull without errors (source)
git stash save --keep-index
Check if there is anything to pull, bring remote up to date (source)
git remote update
Know what you pulled (source)
git diff master master@{1}
Checkout to a remote branch
git checkout -b abranch origin/abranch
Move uncommitted changes to a new branch (source)
git checkout -b <new-branch>
git add <files>
git commit
Move uncommitted changes to existing branch (source)
git stash
git checkout branch2
git stash pop
Get commits by certain user (source):
git log --author=<pattern>