1.4 KiB
1.4 KiB
Git
Config
Aliases:
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.cl clone
git config --global alias.co checkout
git config --global alias.df diff
git config --global alias.lg log
git config --global alias.pl pull
git config --global alias.ps push
git config --global alias.st status
git config --global alias.sw switch
Use nice editor when commit:
git config --global core.editor <editor>
Always pull rebase:
git config --global pull.rebase true
Set default branch to main
:
git config --global init.defaultBranch main
Always fetch/pull prune:
git config --global fetch.prune true
Commands
Prefer rebase when pull:
git pull --rebase
Clean outdated branches:
git fetch --prune
Push force safely:
git push --force-with-lease
Rewrite history by changing last x
commits :
git rebase -i HEAD~<x>
Squash last x
commits to 1 commit:
git reset HEAD~<x>
git add -A
git commit
Cleanup unnecessary files:
git gc
Find common ancestor:
git merge-base <A> <B>
Log:
git log --pretty=oneline
git log --graph --pretty=oneline
git log --date=human
Changelog:
git shortlog <commit>..HEAD
Clean untracked files and folders:
git clean -fd
# If afraid
git clean -fdn