Skip to content

Instantly share code, notes, and snippets.

@brennanMKE
Last active June 6, 2025 23:57
Show Gist options
  • Save brennanMKE/ba7ad70c1238bfd726dc63cb6bcf8b03 to your computer and use it in GitHub Desktop.
Save brennanMKE/ba7ad70c1238bfd726dc63cb6bcf8b03 to your computer and use it in GitHub Desktop.
Essential Git Aliases

Essential Git Aliases

The following Git aliases are very helpful for my usual workflow.

[alias]
	cm = commit -m
	rcm = !git commit --ammend -m
	publish = !git push --set-upstream origin $(git rev-parse --abbrev-ref HEAD)
	discard = restore --staged --worktree .
	shove = push -f
	nudge = push --force-with-lease
	sw = switch
	cb = switch -c
	wip = commit -m wip
	fixup = !git reset --soft HEAD~1 && git commit --amend --no-edit
	co = checkout
	cp = cherry-pick
	rb = rebase
	rr = pull --rebase origin
	ro = remote get-url origin
	rnb = branch -m
	rfs = git rebase --force -S
	dag = log --graph --format='format:%C(yellow)%h%C(reset) %C(blue)\"%an\" <%ae>%C(reset) %C(magenta)%cr%C(reset)%C(auto)%d%C(reset)%n%s' --date-order
	lag = log --graph --all --format='format:%C(yellow)%h%C(reset) %C(blue)\"%an\" <%ae>%C(reset) %C(magenta)%cr%C(reset)%C(auto)%d%C(reset)%n%s' --date-order
	parent = "!git show-branch | grep '*' | grep -v \"$(git rev-parse --abbrev-ref HEAD)\" | head -n1 | sed 's/.*\\[\\(.*\\)\\].*/\\1/' | sed 's/[\\^~].*//' #"
	opendiff = difftool --no-prompt --tool opendiff --dir-diff
	snp = push -set-upstream origin
	dp1 = clone --depth 1
	lrb = !sh -c '\nten_days_ago=$(date -v-30d +%Y-%m-%d) &&\ngit for-each-ref --sort=committerdate --format \"%(committerdate:short) %(refname:short)\" refs/heads/ |\nawk -v date=\"$ten_days_ago\" \"\\$1 >= date { print }\"\n'

Create a branch

git cb new-branch

Switch branch

git sw other-branch

Work in Progress

Commits current changes with "wip" as the commit message. It is helpful to create several commits as checkpoints during development on a feature branch.

git wip

Rebase Remote

Pulls from origin and rebases current branch. This is helful to stay current on a feature branch during development.

git rr main

Fix up

Combines latest commit with the previous commit and uses the commit message of the previous commit. This is great for combining a WIP commits before pushing to a remote branch.

git fixup

Push changes to new remote

git publish

Force push (safe)

git nudge

Force push (unsafe)

git shove

List recent branches

List the 10 most recent and shows date. This is useful for changing between the main branch and feature branches.

git lrb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment