Last active
May 18, 2022 11:49
-
-
Save sidola/e9596e45aac6cde3742b71619a67eec0 to your computer and use it in GitHub Desktop.
Misc 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
[alias] | |
# Undo the latest commit without deleting the files | |
pop-head = reset HEAD~1 | |
# Force push with a lease | |
# https://git-scm.com/docs/git-push#Documentation/git-push.txt---no-force-with-lease | |
push-lease = push --force-with-lease | |
# Rename the previous commit | |
rename = commit --amend | |
# Lists all branches | |
branches = branch -l | |
# Lists all stashes | |
stashes = stash list | |
# Amends the previous commit | |
forgot = commit --amend --no-edit | |
# Stages everything and amends the previous commit | |
forgot-all = !git add -A && git commit --amend --no-edit | |
# Stages everything and creates a new commit with the message "Housekeeping" | |
housekeeping = !git add -A && git commit -m "Housekeeping" | |
# Pushes new branch to origin | |
pushup = "!f() { \ | |
curr_branch=$(git branch --show-current); \ | |
git push --set-upstream origin $curr_branch; \ | |
}; \ | |
f" | |
# Stashes everything, pulls, and then pops the stash | |
spull = "!f() { \ | |
stash_count=$(git stash list | wc -l); \ | |
echo '> Stashing...'; \ | |
git stash --quiet; \ | |
echo '> Pulling...'; \ | |
git pull; \ | |
new_stash_count=$(git stash list | wc -l); \ | |
if [[ $stash_count != $new_stash_count ]]; then \ | |
echo '> Re-applying stashed changes..'; \ | |
git stash pop --quiet; \ | |
fi; \ | |
}; \ | |
f" | |
# (DANGEROUS) Deletes the current branch you're on and checks out | |
# master. The use-case is cleaning up after a PR is merged. | |
cutbranch = "!f() { \ | |
curr_branch=$(git branch --show-current); \ | |
if [[ $curr_branch == 'master' ]]; then \ | |
echo '> You are on the master branch!'; \ | |
echo '> Aborting...'; \ | |
return; \ | |
fi; \ | |
git checkout master; \ | |
echo '> Deleting branch: '$curr_branch; \ | |
git branch -d $curr_branch; \ | |
}; \ | |
f" | |
# Shorthands | |
co = checkout | |
cob = checkout -b | |
st = status -s | |
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative --no-merges |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment