Cheatography
https://cheatography.com
Git useful commands and stuff
Useful Commands
Which commit does this branch come from? git merge-base new_branch old_branch
|
Which merged branches were not deleted? for branch in `git branch -r --merged origin/master | grep -v HEAD`;do echo -e `git show --format="%ai %ar by %an" $branch | head -n 1` \\t $branch; done | sort -r
|
How to amend a (non-pushed) commit? git commit --amend --no-edit
|
How to clear local tags git fetch --prune origin "+refs/tags/*:refs/tags/*"
|
How to display information about origin?
|
How to setup the upstream of branch? git checkout --track origin/branchname
|
How to reset local branch to remote's HEAD?
|
How to check out more than one branch at a time?
|
|
.gitconfig
[core]
excludesfile = ~/.gitignore
autocrlf = false
eol = lf
[include]
path = ~/.gitconfig-local
[fetch]
prune = true
[push]
autoSetupRemote = true
default = upstream
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
meta = yellow bold
frag = magenta bold
old = red bold
new = green bold
[color "status"]
added = yellow
changed = green
untracked = cyan
remoteBranch = cyan
[alias]
lg = log --graph --oneline
hist = lg --decorate --all
st = status -sb
co = checkout
br = branch
pushf = push --force-with-lease
ver = describe --tags
fuckup = commit --fixup HEAD
praise = blame
|
|
|
diff & stash
How to include stage in diff?
|
How to diff words instead of lines?
|
What has changed in a file? git diff HEAD~1..HEAD file.txt
|
How to diff a file with main? git diff HEAD..main file.txt
|
How to diff a stash with the commit it's based on?
|
How to see the most recent stash? git stash show -p stash@{0}
|
Workflow
git fetch
git checkout feature/feature-x
git commit -m "Add feature x"
git push
git checkout develop
git pull
git checkout feature/feature-x
git rebase develop
git add fixed files list
git rebase --continue
git checkout develop
git merge --no-ff feature/feature-x
git push
git branch -D feature/feature-x
git push origin :feature/feature-x
|
Log
|
|
|
git log --follow --pretty=format:'%an (%ae)' file.c | sort | uniq
|
|
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets
More Cheat Sheets by alexandreceolin