Last active
February 26, 2025 12:30
-
-
Save n1kk/322e7b4881ccfa03faced07a758d6742 to your computer and use it in GitHub Desktop.
git aliases
This file contains hidden or 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
# https://gist.github.com/n1kk/322e7b4881ccfa03faced07a758d6742 | |
[alias] | |
aliases = config --get-regexp alias | |
current-branch = rev-parse --abbrev-ref HEAD | |
default-branch = config --get init.defaultBranch | |
default-remote-branch = !basename $(git symbolic-ref --short refs/remotes/origin/HEAD) | |
current-branch = rev-parse --abbrev-ref HEAD | |
last-stash-branch = !git stash list -1 | cut -d':' -f2 | rev | cut -d' ' -f1 | rev | |
# fetch specified branch and switch to it in one go | |
fresh = "!f() {\ | |
if git config remote.origin.url > /dev/null; then\ | |
if [[ $(git current-branch) == $1 ]]; then\ | |
git pull;\ | |
return;\ | |
else\ | |
git fetch origin $1:$1;\ | |
fi;\ | |
else\ | |
echo no remote;\ | |
fi;\ | |
git switch $1;\ | |
}; f" | |
main = fresh main | |
master = fresh master | |
# stash current changes and switch to fresh main | |
# TODO: save current branch name to | |
shelve = "!f() { \ | |
git stash push --include-untracked $@;\ | |
git fresh $(git default-branch);\ | |
}; f" | |
# stash current changes and switch to fresh main | |
unshelve = "!f() { \ | |
git switch $(git last-stash-branch);\ | |
git stash pop $@;\ | |
}; f" | |
# push new local branch that does not exist on remote | |
publish = push -u origin HEAD | |
# remove all local branched that were deleted on remote | |
cleanup = !git fetch -p && git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -d | |
# start ssh agent to save git password for current session | |
# useage: eval `git agent` | |
agent = "!echo 'eval `ssh-agent`; ssh-add ~/.ssh/__YOUR_PRIVATE_KEY__'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment