configure user globally
git config --global "[email]"
git config --global "[name]"
configure user locally (single repository)
git config "[email]"
git config "[name]"
remember login (unix)
git config --global credential.helper cache
remember login (windows)
git config --global credential.helper wincred
update credential cache timeout for single repo in seconds
git config credential.helper 'cache --timeout=300'
change editor to vim
git config --global core.editor "vim"
change line endings to windows based line endings:
git config --global core.autocrlf false
change branch to push to (gerrit)
git config remote.origin.push HEAD:refs/for/master
show colors
git config --global color.ui auto
config file for ignoring files

git config file

disable most colors
    ui = false
    branch = false
    diff = false
    interactive = false
    status = false
    log = false


.gitattributes => defining attributes per path

Set the default behavior, in case people don't have core.autocrlf set.
* text=auto
Convert to os native line endings on checkout.
*.c text
*.h text
Declare files that will always have CRLF line endings on checkout.
*.sln text eol=crlf
Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
possible attributes
text=auto        => The default option. Let git decide.
text eol=crlf    => CRLF endings, even on OSX or Linux. 
text eol=lf      => LF endings, even on windows
binary           => binary, do not change line endings


update repository with all remote branches
git fetch --all

git clone [URL]
git pull --all
git push --all
list remotes
document git remote -v
add new remote
git remote add origin [URL]
git pull --all
git remote set-url origin [NEW_URL]
git push --all
show modified files
git status
show lines changed in files
gir diff
show lines changed in files, ignore whitespace
git diff -w
show lines changed in files, don't use ANSI color codes
git diff --no-color
show lines changed after files have been staged
git status -v
show contents of a single commit
git diff [hash]^..[hash]
git commit, edit message in editor
git commit
commit with message
git commit -m "message"
ammend changes to last commit
git commit --amend
ammend author (name, email)
git commit --amend --reset-author
rebase last 2 commits
git rebase -i HEAD~2
pull and rebase
git pull --rebase
revert single file
git checkout filename
revert a single file to a specified commit
git checkout [hash] [pah_to_file]
all files (will not delete new files)
git reset --hard
delete untracked files and directories
git clean -fd
force the current branch to the specified commit and drop all commits after it (careful!!!)
git reset --hard [commit]
push to a specific remote branch
git push origin [branch]
force overwrite a specific branch. (only if you know what you are doing)
git push origin development -f
git push origin development --force
show a listing of the latest commits
git log
search through commit messages
git log --grep=[query]
show latest commit message for branch
git show development


list local branches
git branch
list remote branches
git ls-remote
git branch -r
checkout local or remote branch
git checkout feature/IT-205
create a local branch
git checkout -b [branch]
create branch based on specified local or remote branch
git branch feature/nieuw --track /branch/to/base/on
delete local branch
git branch -d [branch]
delete local and/or remote branch
git push origin --delete [branch]
create remote branch for local branch
git push -u origin feature/smtp
[branch] onto current branch
git merge [branch]
abort merge
git merge --abort
create reverse commit of merge
git revert -m 1 [hash]
cherry pick a single commit
git cherry-pick [hash]
resolve merge conflict
git add -all
git commit


list all available tags
git tag
show only tags matching a pattern
git tag -l "v1.8.5*"
create a simple tag (commit pointer):
git tag v1.4-lw
create an advanced tag with message:
git tag -a v1.4 -m "my version 1.4"
push tag to origin
git push origin TAG_release_16

git stash

stash uncommitted changes
git stash
git stash push
list changes in stash
git stash list
inspect changes in stash
git stash show
apply stash changes to current commit
git stash apply
stash documentation

ssh keys

generate key without pass phrase
ssh-keygen -t rsa
enable access without login through environment variable (2.3.0)
GIT_SSH_COMMAND="ssh -i [rsa_file]"
export GIT_SSH_COMMAND="ssh -i [rsa_file] -o StrictHostKeyChecking=no"
enable access without login globally or per repo (2.10.0)
git config core.sshCommand "ssh -i ~/.ssh/id_rsa_example -F /dev/null"
enable access without login through ~/.ssh/config
IdentityFile [file]


checking for changes
if git diff-index --quiet HEAD --; then
    # No changes
    # Changes