A list of Git aliases & recipes to Git like a ๐.
# ~/.git/config
[alias]
# List all aliases :)
la = "!git config -l | grep alias | cut -c 7-"
# Clean oneline log
l = log --graph --pretty=format':%C(yellow)%h%C(auto)%d%Creset %Creset%s %C(242)<%an>%Creset'
# Oneline log with dates
ll = log --graph --pretty=format':%C(yellow)%h%C(auto)%d%Creset %Creset%s %C(dim 11)(%ar) %C(246)<%an>%Creset'
# Log with stats
ls = log --pretty=format':%C(yellow)%h%C(auto)%d%Creset %Creset%s %C(242)<%an>%Creset' --stat --no-merges
co = checkout
go = checkout -b
st = status
pr = pull --rebase
br = branch
# current branch
cb = rev-parse --abbrev-ref HEAD
# find parent branch
pb = !"git show-branch -a | ack '\\*' | ack -v \"`git cb`\" | head -n1 | sed 's/.*\\[\\(.*\\)\\].*/\\1/' | sed 's/[\\^~].*//'"
# Show the last tag
lt = describe --tags --abbrev=0
rh = reset --hard
filediff = diff --name-only
last = log -1 HEAD
fixup = commit --fixup
undo = reset HEAD~1 --mixed
# Show the history of a file, with diffs
filelog = log -u
merge-ignore-space = merge -Xignore-all-space
unstage = reset HEAD --
staged = diff --cached
unstaged = diff
track = branch -u
unmerged = branch --no-merged
merged = branch --merged
# Number of commits since ref: git distance <ref>
distance = !git rev-list $1.. --count
authors = shortlog -sn --no-merges
# Search all commits that introduced or removed a string
seek = log --source --all -S
# Show verbose output about tags, branches or remotes
tags = tag -l
branches = branch -a
remotes = remote -v
# delete merged branches
bclean = "!f() { git branch --merged ${1-master} | grep -v " ${1-master}$" | xargs -r git branch -d; }; f"
How a good mainline looks like ->
* (HEAD) Merge branch feature/b
|\
| *
| *
| *
|/
* Merge branch hotfix/foo
|\
| *
|/
* Merge branch feature/a
|\
| *
| *
| *
| *
|/
*
- Pull Rebase
- Rebase before merge and merge with
--no-ff
and--preserve-merges
if needed - Use
git commit โ-fixup
instead of โFix the of the fix of ...โ - Use
git rebase -i <branch> --autosquash
to autosquash fixups - Use
git rebase --onto
to rebase a range of commits onto a changed/different base branch
Enable rerere
to have Git keeping a record of all conflict resolutions and to reapply them if needed
git config --global rerere.enabled true
git config --global rerere.autoupdate true
Been more than 1 hour and still canโt find the cause of the bug? Was working 200 commits back?
git bisect start <bad commit> <good commit>
# got a script you can use to check if something works? i.e. `npm run test`
git bisect run <script>
git revert -m <parent_number> <merge-commit>
git cat-file -p <merge-commit> to show the numbers of the parent commits
git worktree add ../myproject-foobranch foobranch
Use filter_branch
to extract a subfolder of your project as a new repo while retaining all its history
Shorten your ancient history into a single commit using Replace Kicker
Tweaked FrontEndDelight theme for iTerm2
-> Grab it from here