abort-stash

stash workflow

Scenario: You apply a stash but there's a merge conflict. You want to discard all changes so that you can start from a blank slate.
Note that this will discard staged changes, so only use this if you're prepared to discard everything.

Usage: git abort-stash

CLI Command

git config --global alias.abort-stash "!git reset --merge"

.gitconfig Snippet

[alias]
  abort-stash = !git reset --merge

apply-stash

stash workflow

Apply a stash by searching for a partial match in the stash message. Instead of remembering stash numbers, you can use part of the stash description to apply the correct stash. For example, git apply-stash config will apply the most recent stash with "config" in its message.

Usage: git apply-stash <partial-name>

CLI Command

git config --global alias.apply-stash "!f() { stash=$(git stash list | grep -i "$1" | head -n 1); if [ -n "$stash" ]; then stash_id=$(echo "$stash" | awk -F: '{print $1}'); echo "Applying $stash"; git stash apply "$stash_id"; else echo "No stash found matching: $1"; fi; }; f"

.gitconfig Snippet

[alias]
  apply-stash = !f() { stash=$(git stash list | grep -i "$1" | head -n 1); if [ -n "$stash" ]; then stash_id=$(echo "$stash" | awk -F: '{print $1}'); echo "Applying $stash"; git stash apply "$stash_id"; else echo "No stash found matching: $1"; fi; }; f

b

branching

Create a new local branch and check it out immediately.

Usage: git b feature/new-feature

CLI Command

git config --global alias.b "checkout -b"

.gitconfig Snippet

[alias]
  b = checkout -b

bs

branching

List all local branches.

Usage: git bs

CLI Command

git config --global alias.bs "branch --list"

.gitconfig Snippet

[alias]
  bs = branch --list

cdp

branching workflow

Checkout the dev branch and pull the latest changes from the remote. This is a quick way to switch to your main development branch and ensure you have the latest code before starting new work or reviewing changes.

Usage: git cdp

CLI Command

git config --global alias.cdp "!git checkout dev && git pull"

.gitconfig Snippet

[alias]
  cdp = !git checkout dev && git pull

co

branching

Check out a branch.

Usage: git co target-branch

CLI Command

git config --global alias.co "checkout"

.gitconfig Snippet

[alias]
  co = checkout

com

workflow committing

Stage all changes (including new files, modifications, and deletions) and open the commit message editor. This is a quick way to commit all your work from the command line without having to run separate git add and git commit commands.

Usage: git com "commit message here"

CLI Command

git config --global alias.com "!git add -A && git commit -m"

.gitconfig Snippet

[alias]
  com = !git add -A && git commit -m

conf

configuration

Open your git config in your default editor so you can easily review and update it. Save any changes you make, then close the text editor when you're finished. This command will not finish until you close the text editor.

Usage: git conf

CLI Command

git config --global alias.conf "config --global -e"

.gitconfig Snippet

[alias]
  conf = config --global -e

conflicts

merge workflow

List all files that currently have merge conflicts. This is helpful during merge or rebase operations to quickly see which files need conflict resolution, without having to parse through the full output of git status.

Found at https://stackoverflow.com/a/11014518/4051181

Usage: git conflicts

CLI Command

git config --global alias.conflicts "!git ls-files --unmerged | cut -f2 | sort -u"

.gitconfig Snippet

[alias]
  conflicts = !git ls-files --unmerged | cut -f2 | sort -u

cop

branching

Check out a branch by a partial branch name. This function searches for branches containing the provided pattern and checks out the first match.

I name branches with a reference to a work item number, then use the work item number to checkout the right branch. For example, the branch might be called feature/12345-updated-invoice-structure and I can check it out with git cop 12345 or git cop invoice.

From Stack Overflow.

Usage: git cop 12345

CLI Command

git config --global alias.cop "!f() { git branch -a | grep -m1 -e ${1}.*${2} | sed "s/remotes\/origin\///" | xargs git checkout; }; f"

.gitconfig Snippet

[alias]
  cop = !f() { git branch -a | grep -m1 -e ${1}.*${2} | sed "s/remotes\/origin\///" | xargs git checkout; }; f

cor

branching workflow

Checkout a release branch based on a releases/sprint-x naming convention, and pull the latest changes from the remote. Similar to the cdp alias but for the release branch, this quickly switches you to the release branch and ensures you have the most up-to-date code.

Usage: git cor 198.3

CLI Command

git config --global alias.cor "!f() { git checkout releases/sprint-$1 && git pull origin releases/sprint-$1; }; f"

.gitconfig Snippet

[alias]
  cor = !f() { git checkout releases/sprint-$1 && git pull origin releases/sprint-$1; }; f

db

branching

Delete a local branch. Use with caution as this permanently deletes the branch, even if it hasn't been merged.

Usage: git db unwanted-branch

CLI Command

git config --global alias.db "branch -D"

.gitconfig Snippet

[alias]
  db = branch -D

dev

branching merging workflow

Merge latest dev branch code into your current branch and update your local dev branch. Assumes you have a branch called dev both locally and on the origin remote. This alias is useful for keeping your feature branches up-to-date with the latest development work.

This alias pulls the latest dev branch from origin, merges it into your current branch, and updates your local dev branch to match origin/dev.

Usage: git dev

CLI Command

git config --global alias.dev "!git pull origin dev && git merge dev && git fetch origin dev:dev"

.gitconfig Snippet

[alias]
  dev = !git pull origin dev && git merge dev && git fetch origin dev:dev

done

workflow branching

Switch from a feature branch to the latest code in dev branch, and delete branches which are fully merged into dev branch. This alias is intended for use after pushing a code-complete feature branch to the server, when ready to start a new feature based on the latest dev branch code.

Usage: git done

CLI Command

git config --global alias.done "!git fetch && git checkout dev && git pull && git merged && git status"

.gitconfig Snippet

[alias]
  done = !git fetch && git checkout dev && git pull && git merged && git status

f

remote

Fetch latest changes from the server and remove references to deleted remote branches.

Usage: git f

CLI Command

git config --global alias.f "fetch --prune"

.gitconfig Snippet

[alias]
  f = fetch --prune

merged

workflow branching

Delete local branches which have been fully merged into dev branch (excluding the dev branch itself). Useful for cleaning up completed feature branches.

From Advanced Git Aliases published by Atlassian.

Usage: git merged

CLI Command

git config --global alias.merged "!f() { git branch --merged dev | grep -v " dev$" | xargs -r git branch -d; }; f"

.gitconfig Snippet

[alias]
  merged = !f() { git branch --merged dev | grep -v " dev$" | xargs -r git branch -d; }; f

merged-into

workflow branching

Delete all local branches that have been fully merged into the specified branch. Similar to the merged alias but allows you to specify any branch name as the target. For example, git merged-into main will delete all branches merged into main.

Usage: git merged-into <branch-name>

CLI Command

git config --global alias.merged-into "!f() { git branch --merged "$1" | grep -v " $1$" | xargs -r git branch -d; }; f"

.gitconfig Snippet

[alias]
  merged-into = !f() { git branch --merged "$1" | grep -v " $1$" | xargs -r git branch -d; }; f

npmci

workflow tools npm

Run npm ci in all directories that contain a package.json file. This is useful in monorepo setups or projects with multiple npm packages, allowing you to install all dependencies in a single command with clean installs.

Usage: git npmci

CLI Command

git config --global alias.npmci "!f() { git ls-files "*/package.json" | sed "s|/[^/]*$||" | sort -u | xargs -I {} sh -c "echo 'Running npm ci in {}' && cd {} && npm ci"; }; f"

.gitconfig Snippet

[alias]
  npmci = !f() { git ls-files "*/package.json" | sed "s|/[^/]*$||" | sort -u | xargs -I {} sh -c "echo 'Running npm ci in {}' && cd {} && npm ci"; }; f

npmi

workflow tools npm

Run npm install in all directories that contain a package.json file. Similar to npmci but uses npm install instead of npm ci, allowing package-lock.json to be updated if needed. Useful for updating dependencies across multiple packages in a monorepo.

Usage: git npmi

CLI Command

git config --global alias.npmi "!f() { git ls-files "*/package.json" | sed "s|/[^/]*$||" | sort -u | xargs -I {} sh -c "echo 'Running npm i in {}' && cd {} && npm i"; }; f"

.gitconfig Snippet

[alias]
  npmi = !f() { git ls-files "*/package.json" | sed "s|/[^/]*$||" | sort -u | xargs -I {} sh -c "echo 'Running npm i in {}' && cd {} && npm i"; }; f

open

workflow tools

Open a file in Notepad++ directly from the Git command line.

Explanation

Open the first file whose filename (not path) contains the specified search term.
Intended usage is for a complete or partial file name - does not match against directory names.
File is opened in Notepad++ and the alias assumes this is installed in C:/Program Files/Notepad++
Tested in powershell, command prompt, and git bash.
Explanation:
root is the file path to the git repository.
file is the file path within the repository for the first file found matching the search term.
Uses grep/findstr to match only against the basename (filename) portion of the path, not directories.
Checks if grep is available and uses it, otherwise falls back to a Windows-compatible approach.
Validates that a file was found before attempting to open it.
Calculates root and file, then starts notepad++.exe and passes the absolute file path in.
Note that it uses start so that the command finishes executing without waiting for notepad++ to close.

Usage: git open ExportFxTransactionCommand.cs

CLI Command

git config --global alias.open "!f() { root=$(git rev-parse --show-toplevel); if command -v grep >/dev/null 2>&1; then file=$(git ls-files | grep -m1 "/[^/]*$1[^/]*$"); else file=$(git ls-files | findstr /R "[^/]*$1[^/]*$" | head -1); fi; if [ -n "$file" ]; then start "" "C:\Program Files\Notepad++\notepad++.exe" "$root/$file"; else echo "No file found matching: $1"; fi; }; f"

.gitconfig Snippet

[alias]
  open = !f() { root=$(git rev-parse --show-toplevel); if command -v grep >/dev/null 2>&1; then file=$(git ls-files | grep -m1 "/[^/]*$1[^/]*$"); else file=$(git ls-files | findstr /R "[^/]*$1[^/]*$" | head -1); fi; if [ -n "$file" ]; then start "" "C:\Program Files\Notepad++\notepad++.exe" "$root/$file"; else echo "No file found matching: $1"; fi; }; f

pl

remote pull

Pull latest changes. Shorthand for git pull to fetch and merge changes from the upstream branch. Added for consistency with the 2-character ps alias.

Usage: git pl

CLI Command

git config --global alias.pl "pull"

.gitconfig Snippet

[alias]
  pl = pull

ps

remote push

Push commits to a remote branch on the origin remote. If there is no upstream branch on origin, one will be created.

I prefer this alias to running git push because it works regardless of whether or not there is an existing upstream branch.

Usage: git ps

CLI Command

git config --global alias.ps "push -u origin HEAD"

.gitconfig Snippet

[alias]
  ps = push -u origin HEAD

pt

remote push advanced

Push up to a specific commit. This function pushes the current branch up to a specific commit hash. My main use case for this is when making changes to a branch which already has a Pull Request in Azure DevOps. The changes in each push can be reviewed as separate updates to the PR, so I can make a series of commits then push them as multiple logical updates for easier review.

I based this alias on https://coderwall.com/p/hexinq/git-push-up-to-a-certain-commit

Usage: git pt abc123

CLI Command

git config --global alias.pt "!f() { BRANCH=`git symbolic-ref --short HEAD`; git push -u origin ${1}:refs/heads/$BRANCH; }; f"

.gitconfig Snippet

[alias]
  pt = !f() { BRANCH=`git symbolic-ref --short HEAD`; git push -u origin ${1}:refs/heads/$BRANCH; }; f

rename-branch

branching

Rename the current branch.

Usage: git rename-branch new-branch-name

CLI Command

git config --global alias.rename-branch "branch -m"

.gitconfig Snippet

[alias]
  rename-branch = branch -m

s

status workflow

Quick shorthand for git status to quickly check the current state of your working directory and staging area.

Usage: git s

CLI Command

git config --global alias.s "status"

.gitconfig Snippet

[alias]
  s = status

squash

branching merge workflow

Squash commits from the current branch into another branch. This function takes all commits from the current branch and squashes them into a single commit on the target branch. The result is not committed automatically, allowing you to review and write a commit message.

Modified from https://stackoverflow.com/a/37209562/4051181.

Usage: while on 'wip/12345', wanting to squash everything into 'feature/12345', run 'git squash feature/12345'.

Usage: git squash feature/12345

CLI Command

git config --global alias.squash "!f() { BRANCH=`git symbolic-ref --short HEAD`; git checkout ${1}; git merge --squash $BRANCH; }; f"

.gitconfig Snippet

[alias]
  squash = !f() { BRANCH=`git symbolic-ref --short HEAD`; git checkout ${1}; git merge --squash $BRANCH; }; f

start

workflow stash

Stages all changes (including new, modified, deleted, and renamed files) and applies the latest stash. Intended usage is when starting a project where configuration changes are stored in a stash. Before starting the application, we want to apply the latest stash containing the word 'config' but keep them separate from the changes under test (which is why they are staged).

Usage: git start

CLI Command

git config --global alias.start "!git add -A && git apply-stash config"

.gitconfig Snippet

[alias]
  start = !git add -A && git apply-stash config

stash-config

stash workflow

Stash current changes, suffixing the provided message with the word 'config' and the current date & time.

For example, running git stash-config "MyApp working" could create a stash called MyApp working config 2025-12-04 09:37.

Usage: git stash-config "MyApp working"

CLI Command

git config --global alias.stash-config "!f() { git stash -u -m "$1 config $(date +%Y-%m-%d' '%H:%M)"; }; f"

.gitconfig Snippet

[alias]
  stash-config = !f() { git stash -u -m "$1 config $(date +%Y-%m-%d' '%H:%M)"; }; f

stop

workflow

Reverts all unstaged changes to tracked files, and delete all untracked files and directories. Intended usage is when stopping a project where configuration changes are stored in a stash. When we stop the application, we want to revert the unstaged changes (which we are expecting to just be the configuration changes) so we have a clean working directory.

Usage: git stop

CLI Command

git config --global alias.stop "!git checkout -- . && git clean -fd"

.gitconfig Snippet

[alias]
  stop = !git checkout -- . && git clean -fd

uncommit

workflow committing

Undo the latest commit, removing the commit from history and leaving the changes from the commit unstaged.

Usage: git uncommit

CLI Command

git config --global alias.uncommit "reset --mixed HEAD~1"

.gitconfig Snippet

[alias]
  uncommit = reset --mixed HEAD~1

unpushed

remote status

View commits on the current local branch which have not yet been pushed to the server.

Usage: git unpushed

CLI Command

git config --global alias.unpushed "cherry -v"

.gitconfig Snippet

[alias]
  unpushed = cherry -v