Created
August 18, 2021 16:02
-
-
Save carsonoid/d5f65357b7f95966cc11538dfaa9659a to your computer and use it in GitHub Desktop.
Git Bash Helpers
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
#!/bin/bash | |
# Helper funcs usually not used directly | |
git-mainbranch() { git ls-remote --symref origin HEAD | awk -F'[/\t]' 'NR == 1 {print $3}'; } | |
git-fixup() { git commit --fixup HEAD; } | |
git-fixup-all() { git add -A && git commit --fixup HEAD; } | |
git-autosquash() { GIT_SEQUENCE_EDITOR=: git rebase -i --autosquash ${1:-origin/$(git-mainbranch)}; } | |
# Easy shortcut to take all current changes and fix them up into the previous commit | |
auto-fixup() { git-fixup-all; git-autosquash; } | |
# shortcut to interactive rebase regardless of upstream main branch name | |
git-rebase-main() { git rebase -i origin/$(git-mainbranch); } | |
# re-creates the last commit without actually changing any files | |
# this can be useful to re-trigger ci/cd pipelines that operate on commit | |
# but it will require a force push | |
git-recommit() { | |
date > .gitrecommit | |
git add .gitrecommit | |
git-fixup | |
git rm .gitrecommit | |
git-fixup | |
git-autosquash | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment