Git: Commands & Aliases
Useful commands and aliases for a better Git experience.
15. Nov 2023 toc: disabled view: slimMy git aliases explained:
git st
= Statusgit cm
= Commit with messagegit co
= Checkoutgit ap
= Append modegit cob
= Checkout new branchgit brd
= Delete branchgit br
= List all branchesgit ll
= Show all commitsgit lg
= Show all commits as graphgit lf
= Show all commits which includes changes from a specific filegit df
= Show changesgit c
= Open commit viewgit p
= Pullgit f
= Fetchgit save
= Create a checkpoint commitgit undo
= Undo last local commit (committed changes get move to index)git wipe
= Delete all changesgit erase
= Delete all changes and all new filesgit done
= Push new branch to remote
My git alias config section:
[alias]
st = status -sbu
cm = commit -m
co = checkout
ap = !git add -N . && git add -p
cob = checkout -b
brd = branch -D
br = branch --format='%%(color:yellow)%%(HEAD)%%(color:reset) %%(color:blue)%%(refname:short)%%(color:reset) %%(contents:subject) - %%(color:green)%%(authorname)%%(color:reset)' --sort=-committerdate
ll = log --abbrev-commit --format='%%C(blue)%%h%%C(reset) %%C(yellow)%%d%%C(reset) %%s - %%C(green)(%%cr) [%%an]%%C(reset)'
lg = log --graph --abbrev-commit --format='%%C(blue)%%h%%C(reset) %%C(yellow)%%d%%C(reset) %%s - %%C(green)(%%cr) [%%an]%%C(reset)'
lf = log --follow --abbrev-commit --format='%%C(blue)%%h%%C(reset) %%C(yellow)%%d%%C(reset) %%s - %%C(green)(%%cr) [%%an]%%C(reset)'
ls = stash list
df = diff
c = commit
p = pull
f = fetch
undo = reset HEAD~1 --mixed
wipe = !git restore .
erase = !git reset --hard
done = !git push origin HEAD
My git workflow for feature implementation:
git p
git cob feat/example
...
git ap
git c
git done
Git Patches
Creating a patch:
git diff > example.patch
Applying a patch:
git apply example.patch