Skip to content

Instantly share code, notes, and snippets.

@kavun
Last active February 22, 2018 19:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kavun/32235fde17fdd33a84b57a3c65a7f7ac to your computer and use it in GitHub Desktop.
Save kavun/32235fde17fdd33a84b57a3c65a7f7ac to your computer and use it in GitHub Desktop.
git cheatsheet

Git Cheatsheet

for sourcetree users

basics

  • list local branches git branch
  • git fetch origin
  • git pull origin <branch> (try with --ff-only first, so you can bail or change things if merge or rebase is needed)
  • git checkout <branch>
  • git checkout -b <branch> --track <remote>/<branch>
  • git merge --no-ff <branch>
  • git push --tags origin <branch>
  • discard file git checkout -- <path>
  • discard everything git reset --hard HEAD
  • unstage file git reset HEAD <path>
  • git branch <branch>
  • git add -i ftw
  • git tag -l "v*"
  • git tag -a v0.0.0

conflicts

clean up

  • git clean -dxn
  • then git clean -dxf
  • -n is dry run
  • -f if force
  • -x is to clean ignored files

stash

diff

  • git show <commit>
  • git show <commit>:<file>
  • git log --stat -1 <commit>

logging

  • git log --oneline --decorate --graph -5 HEAD
  • git log --oneline --decorate --graph --dirstat -5 HEAD
  • git log --oneline --decorate --graph --stat -1 <commit>
  • search log by commit git log --oneline --all --grep="find me"
  • --no-merges
  • --first-parent
  • git log --cherry master..<branch> commits not yet merged to master https://kevinareed.com/2015/12/12/cherry-logging-git-branches/
  • git cherry -v master <branch> commits not yet merged to master
  • To list branches with commits not merged into master: git branch --no-merged master

.gitconfig

[core]
	autocrlf = true
	editor = code --wait
[log]
	date = short
[format]
	pretty = decoratedatename
[pretty]
	decoratedatename = format:%C(auto,yellow)%h %C(auto,blue)%>(10,trunc)%ad %C(auto,green)%<(6,trunc)%ae%C(auto)%d %C(auto,reset)%s
[diff]
	tool = p4merge
[merge]
	tool = p4merge
[push]
	default = upstream
[alias]
	logg = log --graph
	logf = log --first-parent
	pullff = pull --ff-only
	mergecommit = merge --no-ff
[filter "lfs"]
	required = true
	clean = git-lfs clean -- %f
	smudge = git-lfs smudge -- %f
	process = git-lfs filter-process
[difftool "sourcetree"]
	cmd = 'C:/Program Files/Perforce/p4merge.exe' \"$LOCAL\" \"$REMOTE\"
[mergetool "sourcetree"]
	cmd = 'C:/Program Files/Perforce/p4merge.exe' \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"
	trustExitCode = true
[difftool "p4merge"]
	cmd = 'C:/Program Files/Perforce/p4merge.exe' \"$LOCAL\" \"$REMOTE\"
[mergetool "p4merge"]
	cmd = 'C:/Program Files/Perforce/p4merge.exe' \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"
	trustExitCode = true

aliases

gitpushmerge=git fetch && git checkout $1 && git pull && git push && git checkout $2 && git pull && git merge --no-ff $1 && git push && git checkout $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment