Git

Cheats

Interactively choose parts (hunks) of files to stage

git add -p

Show the commit history and associated patches for a specific file

git log -p <file_name>

Quickly view the changes in the working directory since the last commit

git diff --stat

Display the branch history with decoration to see where branches have split or merged

git log --oneline --decorate --graph

Customize the format of the git log output

git log --pretty=format:"%h - %an, %ar : %s"

Find text in commit messages (useful for locating specific changes)

git log --grep="<text>"

Stash changes in the working tree, including untracked files

git stash save -u

Create an empty commit, useful while testing branch protection rules

git commit --allow-empty -m "Empty commit message"

Set the git output pager to quit when the output is less than one screen, and not clear the screen after displaying

git config --global core.pager 'less -RFX'

Use Git's auto-correct feature to fix mistyped commands

git config --global help.autocorrect 1

List aliases for Git commands

git config --get-regexp alias

Perform a dry run of merging without actually merging branches

git merge --no-commit --no-ff <branch_name>

Show a tree-like representation of the repo's structure

git ls-tree --name-only -r -t HEAD

On this page