Last active
October 25, 2023 08:06
-
-
Save aclima93/a6a13d70ce895c08ad0afa8589cafc33 to your computer and use it in GitHub Desktop.
useful git aliases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[user] | |
name = António Lima | |
email = <user@organization> | |
[alias] | |
# list aliases | |
alias = "!git config --get-regexp ^alias\\. | sed -e s/^alias\\.// -e s/\\ /\\ =\\ /" | |
# push to origin [branch_name] | |
puo = "push --set-upstream origin --no-verify" | |
# show commit tree | |
logtree = "log --graph --oneline --decorate --all" | |
# list commits [-num_to_list] | |
lc = "log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short" | |
# list commits with modifyed files | |
lcm = "log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --numstat --date=sh" | |
# show modified files in last commit | |
mlc = "!git ll -1" | |
# show diff of last commit | |
dlc = "diff --cached HEAD^" | |
# find file path ["string of words to search"] | |
ffp = "!git ls-files | grep -i" | |
# search entire codebase for ["string of words to search"] | |
grep = "grep -Ii" | |
# reset the current branch to the origin status | |
gud = "reset --hard" | |
# create a branch, check it out, and push it upstream (replaces spaces with hyphens) | |
bcp = "!f() { \ | |
branch_name=$(echo $1 | sed 's/ /-/g'); \ | |
git branch $branch_name; \ | |
git checkout $branch_name; \ | |
git puo $branch_name; \ | |
}; f" | |
# create the dev branch | |
dev = "!f() { \ | |
git bcp "dev/$*"; \ | |
}; f" | |
# create the feature branch | |
feature = "!f() { \ | |
git cp master; \ | |
git bcp "feature/$*"; \ | |
}; f" | |
# create the feature and dev branches, in that order | |
# (using the `$*` expansion because of strings with spaces being parsed as separate arguments later on) | |
feature-dev = "!f() { \ | |
git feature "$*"; \ | |
git dev "$*"; \ | |
}; f" | |
# attempt to force the push, but halt and revert if an issue arises | |
pfwl = "push --force-with-lease" | |
# when pulling, resolve with a rebase | |
pr = "pull --rebase" | |
# checkout a branch and pull | |
cp = "!f() { \ | |
git checkout $1; \ | |
git pull; \ | |
}; f" | |
# fetches branch updates without switching to it | |
update = "!f() { git fetch origin $1:$1; }; f" | |
# removes local branches that have already been merged to the target branch (defaults to master) | |
bclean = "!f() { \ | |
DEFAULT="master"; \ | |
git branch --merged ${1-$DEFAULT} | grep -v " ${1-$DEFAULT}$" | xargs git branch -d; \ | |
}; f" | |
# quick-save: stashes all changes and re-applies them | |
qs = "!f() { \ | |
git stash; \ | |
git stash apply; \ | |
}; f" | |
# quick-load: discard all local changes and apply the last stash | |
ql = "!f() { \ | |
git reset --hard; \ | |
git stash apply; \ | |
}; f" | |
# create and push tag at HEAD | |
tp = "!f() { \ | |
git tag $1; \ | |
git push origin $1; \ | |
}; f" | |
# commit messages since last release and up until specified date | |
release-log = "!f() { git log $(git describe --tags --match "*appstore*" --abbrev=0 @^)..@ --format=%B --before=$1; }; f" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment