gitconfig--globaluser.name"John Doe"gitconfig--globaluser.email"john@example.com"gitconfig--globalcore.editorvim
gitconfig--globalinit.defaultBranchmain
gitconfig--globalpull.rebasetrue# rebase on pull by defaultgitconfig--list# show all configgitconfig--list--show-origin# show config + file source
gitstatus
gitstatus-s# short formatgitadd<file>
gitadd.# stage all changesgitadd-p# interactive hunk staginggitdiff# unstaged changesgitdiff--staged# staged vs last commitgitcommit-m"message"gitcommit-am"message"# stage tracked files + commitgitcommit--amend# edit last commit (message or content)gitcommit--amend--no-edit# amend without changing message
gitbranch# list local branchesgitbranch-a# list all (local + remote)gitbranch<name># create branchgitbranch-d<name># delete (safe)gitbranch-D<name># force deletegitbranch-m<old><new># renamegitswitch<branch># switch branchgitswitch-c<name># create + switchgitcheckout-b<name>origin/<branch># track remote branch
gitlog
gitlog--oneline
gitlog--oneline--graph--all# visual branch graphgitlog--oneline-10# last 10 commitsgitlog--author="John"gitlog--since="2 weeks ago"gitlog--<file># history of a filegitlog-p<file># history with diffsgitshow<commit>
gitshowHEAD~2# 2 commits before HEADgitblame<file>
gitblame-L10,20<file># blame specific lines
gittag# list tagsgittag<name># lightweight taggittag-a<name>-m"message"# annotated taggittag-a<name><commit># tag a past commitgitpushorigin<tag>
gitpushorigin--tags
gittag-d<name># delete local taggitpushorigin--delete<tag># delete remote tag
# Sign a commitgitcommit-S-m"message"# Sign last commit (amend)gitcommit-S--amend--no-edit
# Sign the last 5 commitsgitrebase--signoffHEAD~5
# Check signature in loggitlog--show-signature
gpg failed to sign the data
If you get error: gpg failed to sign the data, run:
#!/usr/bin/env bashWHITELIST="master|main|prod"gitfetch--prune
TO_REMOVE=$(gitbranch--merged|grep-Ev"(^\*|${WHITELIST})")if[-z"${TO_REMOVE}"];thenecho"No branches to remove."elseecho"Branches to remove:"echo"${TO_REMOVE}"echo""read-n1-s-r-p$'Press any key to continue...\n'KEY
if["${KEY}"=''];thenecho"${TO_REMOVE}"|xargs-n1gitbranch-d
fifi