Index

GIT

config

git config --global user.email "you@example.com"
git config --global user.name "[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
config file for ignoring files
.gitignore
enable scripted access to git repo without requiring manual login
chmod 600 [rsa_file]
export GIT_SSH_COMMAND="ssh -i [rsa_file] -o StrictHostKeyChecking=no"
git clone ssh://example.com/repo.git
generate key without pass phrase
ssh-keygen -t rsa

gitattributes

.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

common

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]
migrate
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 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
rebase last 2 commits
git rebase -i HEAD~2
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]
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

Branches

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

Tags

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