My git aliases
05 Apr 2019 by Nigel SampsonI’ve seen a few posts around lately with people discussing how they work with git during day to day development and I thought I’d share mine.
I use a combination of GitHub Desktop and the command line. I prefer a UI for crafting my commits, being able to select which files and / or lines I’d like to include is incredibly easy in the UI.
For everything else such as rebasing, pulling etc I use the command line, usually Powershell inside Cmder and using posh-git.
Below are the aliases I use reasonably consistently, one theme through these is that I’m not optimising for keystrokes, but “brain space”.
graph = log --oneline --graph --decorate --all
branches = branch -a
tags = tag
stashes = stash list
unstage = reset -q HEAD --
discard = checkout --
uncommit = reset --mixed HEAD~
amend = commit --amend --no-edit
nevermind = !git reset --hard HEAD && git clean -xdf
remotes = remote -v
fixup = commit --fixup
overwrite = push --force-with-lease
rewrite="!f() { \
COMMIT_COUNT=$(git rev-list --count HEAD ^master); \
git rebase -i --autosquash HEAD~$COMMIT_COUNT; \
};f"
publish="!f() { \
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD); \
git push -u origin $BRANCH_NAME; \
};f"
browse = "!f() { \
REPO_URL=$(git config remote.origin.url); \
start ${REPO_URL%%.git}; \
};f"
pr = "!f() { \
REPO_URL=$(git config remote.origin.url); \
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD); \
start \"${REPO_URL%%.git}/compare/${BRANCH_NAME}?expand=1\"; \
};f"
jira = "!f() { \
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD); \
start \"https://pushpay.atlassian.net/browse/${BRANCH_NAME}\"; \
};f"
Hope others find these useful.