Git: Commands & Aliases

Useful commands and aliases for a better Git experience.

15. Nov 2023

My git aliases explained:

  • git st = Status
  • git cm = Commit with message
  • git co = Checkout
  • git ap = Append mode
  • git cob = Checkout new branch
  • git brd = Delete branch
  • git br = List all branches
  • git ll = Show all commits
  • git lg = Show all commits as graph
  • git lf = Show all commits which includes changes from a specific file
  • git df = Show changes
  • git c = Open commit view
  • git p = Pull
  • git f = Fetch
  • git save = Create a checkpoint commit
  • git undo = Undo last local commit (committed changes get move to index)
  • git wipe = Delete all changes
  • git erase = Delete all changes and all new files
  • git 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