Skip to content

Instantly share code, notes, and snippets.

@WattyRev
Last active August 23, 2022 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WattyRev/764b95c6c92c868788d8e8b2f3a04461 to your computer and use it in GitHub Desktop.
Save WattyRev/764b95c6c92c868788d8e8b2f3a04461 to your computer and use it in GitHub Desktop.
Aliases for pushing branches to remote, and delete remove branches
[core]
editor = code --wait
[alias]
co = checkout
br = branch
ci = commit
st = status
me = merge
pul = pull
pus = push
mer = merge
merg = merge
cp = cherry-pick
# Removes references to remote branches that no longer exist
p = "!f() { git remote prune origin; }; f"
# Opens all conflicted items in Atom
fix = "!f() { git diff --name-only | uniq | xargs code --wait; }; f"
# Sets the current branch's upstream to origin/<branch name> and pushes
pushup = "!gitbranchname() { git symbolic-ref --short HEAD; }; gitpushupstream() { git push --set-upstream origin `gitbranchname`; }; gitpushupstream"
# Deletes the remote version of the current branch
deleter = "!gitbranchname() { git symbolic-ref --short HEAD; }; gitdeleteremote() { git push origin --delete `gitbranchname`; }; gitdeleteremote"
# Delete a branch locally and remotely. e.g. git delete my-branch
delete = "!f() { git branch -D $1; git push origin --delete $1; }; f"
del = "!f() { git branch -D $1; git push origin --delete $1; }; f"
# Commit all changes with the JIRA ticket name (found in branch name) prepended to the commit message
# e.g. git cim "my commit message"
cim = "!f() { \
if [[ -z $1 ]]; \
then \
echo "Error: No commit message provided."; \
exit 1; \
else \
local ticketId=$(git rev-parse --abbrev-ref HEAD | grep -Eo "[A-Z]+-[0-9]+"); \
if [[ -z $ticketId ]]; \
then git commit -a -m \"$1\" ${@:2}; \
else git commit -a -m \"$ticketId $1\" ${@:2}; \
fi; \
fi; \
}; f"
# List uniq jira ticket numbers found in git log. e.g `git jiralog [EARLIER_COMMIT_HASH]..[LATER_COMMIT_HASH]`
jiralog = "!f() { git log $1 | grep -Eo '([A-Z]{2,}-)([0-9]+)' | sort -u; }; f"
# Quickly pull before pushing
quickpush = "!f() { git pull --no-edit && git push; }; f"
# Squash commits since first argument using second argument as commit message
# e.g. git squash master "All my changes together"
squash = "!f() { git reset --soft $1 && git commit -m $2; }; f"
emptyCommit = "!f() { git commit --allow-empty -m \"Empty Commit\"; }; f"
[pager]
branch = false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment