Table of Contents
Reference sheet by topic: http://ndpsoftware.com/git-cheatsheet.html
# create new branch off current master/HEAD
git checkout -b <branch> # create new branch off current branch's HEAD
git push -u origin <branch> # push local branch to remote "origin" and track in local branch
# commit changes locally
git add -A :/ # state all local changes, incl. new (=untracked) files
git commit -m "JIRA-XXXX, your message"
# push current branch to server
git push
# delete local & remote branch
git branch -d <branch>
git push origin --delete <branch>
# update remote branch info (refresh all remotes' branches, add new ones and removing deleted ones)
git remote update --prune
## Ensure repo is in clean state
a) either clone
git clone https://....
b) or clean working dir
git clean -dfx
# bring master + branch up2date
git checkout <branch> && git pull
git checkout master && git pull
# merge master into branch -> branch MUST be up2date! (hence --ff-only !)
git merge --ff-only origin/master
# if desired merge branch into master, ensure branch info is preserved (hence --no-ff)
git checkout master
git merge --no-ff <branch> # merge branch into master
# run build+tests
e.g. "mvn clean verify -Pjenkins"
# push changes back to remote
git push # push changes back
# delete remote+local branch
git push origin --delete <branch>
git branch -d <branch>
# Git "Pickaxe" to search for commits that introduce or remove a particular line of source code
# (from https://www.atlassian.com/git/tutorials/git-log/filtering-the-commit-history)
git log -S"Hello, World!"
# History of specific file (incl. renames)
git log --follow filename
# History of folder (incl. renames)
git log --follow -- /path/to/folder
# Save "dirty" working folder temporarily with stashing
git stash save [<name>]
# restore saved stash
git stash apply [<name>]
# list stash stack
git stash list
# Configure global settings
git config --global merge.ff false
# checkout a remote branch and track local (assumes remote branch exists)
git checkout -b JIRA-xxx origin/JIRA-xxx
# fetch latest remote repository info for currently tracked branchs
git fetch
# fetch all branches
git fetch --all
# stage all changes (file adds/modify/removes, inkl untracked) in the local copy
git add -A :/
# discard local changes to tracked files+dirs
git reset --hard
# remove untracked files, incl ignored files + dirs
git clean -dx
# create new local branch directly off remote branch
git fetch --all # get latest changes
git checkout -b JIRA-xxxx origin/master
git pull
# display commit log incl changed files:
git log --stat --pretty
# display local commits not pushed yet on current branch:
git log origin/master..master
# display any local commits on any branch not pushed yet:
git log --branches --not --remotes
# delete remote branch
git push origin --delete <branch>
# update list of remote branches
git remote update -p
# display branch graph
git log --graph --all --oneline
git log --oneline --all --graph --decorate
# display what changed between current branch and other branch
git whatchanged ..origin/master
# clean all local branches except master (from https://coderwall.com/p/x3jmig/remove-all-your-local-git-branches-but-keep-master)
git config --global alias.clean-branches "!git branch | grep -v master | xargs git branch -d"
# make sure master is up2date
git checkout master
git pull --rebase
# merge the feature branch, but don't commit -> shows the changes as uncommitted changeset
git merge --no-commit --no-ff origin/JIRA-xxxx
# reset changes
git reset --hard
# Turn off fast-forward for merges
git config --global merge.ff false # use --global for personal settings
#If you are using a windows box, use
git config --global core.autocrlf true
#Check your git config using
git config -l
# If your username and email are not set, use
git config --global user.name first.last
git config --global user.email [email protected]
# create useful aliases
git config --global alias.timeline "log --oneline --graph --decorate"
git config --global alias.timeline-all=log --oneline --all --graph --decorate
# core.excludesfile=~/.gitignore_global
git config --global core.excludesfile ~/.gitignore_global
either $repo/.gitconfig or ~/.gitconfig (=--global)
https://gist.github.com/fubhy/6156279
[email protected]
user.name=Max Mustermann
mergetool.keepbackup=true
core.excludesfile=~/.gitignore_global
core.filemode=false
core.ignorecase=false
merge.ff=false # turn off fast-forward for merging
push.default=current
credential.helper=osxkeychain
# branch.autosetuprebase=always # use rebase by default - not recommended
http.postbuffer=524288000 # fur pushing large files
format.pretty=%h, %ad, %s%x09(%an) # change git log output to your liking
log.date=iso
env vars
GIT_SSL_CAINFO=/usr/ssl/certs/ca-bundle.crt
GIT_SSL_NO_VERIFY=true
GIT_CURL_VERBOSE=1
HTTP_PROXY=http://user:[email protected]:3140/
or ~/.gitconfig
[http]
sslCAinfo = /home/radium/certs/cacert.pem
proxy = http://user:[email protected]:3140/
sslverify = false
in ~/.ssh/config
Host bitbucket.example.com
ProxyCommand ssh <user>@hop.server.com -q -W %h:%p
# p4merge
git config --global diff.tool p4mergetool
git config --global difftool.p4mergetool.cmd "/Applications/p4merge.app/Contents/Resources/launchp4merge \$LOCAL \$REMOTE"
git config --global merge.tool p4mergetool
git config --global mergetool.p4mergetool.cmd "/Applications/p4merge.app/Contents/Resources/launchp4merge \$PWD/\$BASE \$PWD/\$REMOTE \$PWD/\$LOCAL \$PWD/\$MERGED"
git config --global mergetool.p4mergetool.trustExitCode false
git config --global mergetool.keepBackup false
# SourceTree
git config --global diff.tool sourcetree
git config --global difftool.sourcetree.cmd opendiff "$LOCAL" "$REMOTE"
git config --global difftool.sourcetree.path
git config --global mergetool.sourcetree.cmd=/Applications/SourceTree.app/Contents/Resources/opendiff-w.sh "$LOCAL" "$REMOTE" -ancestor "$BASE" -merge "$MERGED"
git config --global mergetool.sourcetree.trustexitcode=true
# DiffMerge
git config --global diff.tool diffmerge
git config --global difftool.diffmerge.cmd 'diffmerge "$LOCAL" "$REMOTE"'
git config --global merge.tool diffmerge
git config --global mergetool.diffmerge.cmd 'diffmerge --merge --result="$MERGED" "$LOCAL" "$(if test -f "$BASE"; then echo "$BASE"; else echo "$LOCAL"; fi)" "$REMOTE"'
git config --global mergetool.diffmerge.trustExitCode true
# merge branches
git merge <sourcebranch> (<targetbranch>)
# find merge conflicts:
git status
git ls-files -u
# merging changes using merge tool in case of conflicts:
git mergetool