From 60e77bb0e38b98eba607537f07e12d0d57bc0416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin-Charles=20Guih=C3=A9neuf?= Date: Fri, 23 Oct 2020 09:34:07 +0200 Subject: [PATCH] aliases: Introduce git_parent and associated rebase aliases --- .bash_aliases | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/.bash_aliases b/.bash_aliases index 7d221f1..0428c84 100644 --- a/.bash_aliases +++ b/.bash_aliases @@ -90,6 +90,16 @@ alias cont='git rebase --continue' alias branch_clean='git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d' alias tag_clean='git tag -l | xargs git tag -d && git fetch -t' +function git_parent { + git log --pretty=format:"%D" HEAD^ | \ + grep -v "^$" | \ + grep -v `git rev-parse --abbrev-ref HEAD` | \ + sed "s/, /\n/g" | \ + grep -v "tag:[^,]*,*" | \ + head -n1 | \ + sed "s/origin\/\([^,]*\)/\1/" +} + alias log='git log --graph --decorate --oneline' # Branch @@ -125,33 +135,43 @@ function grb { git rebase --interactive HEAD~$1 } -function grbm { +function grbi { # Save current branch BRANCH=$(git branch | grep \* | cut -d ' ' -f2) - # Checkout master & pull - git checkout master + # Save parent branch + PARENT=$(git_parent) + + # Checkout parent & pull + git checkout ${PARENT} git pull + echo "Rebasing on" ${PARENT} + # Back to previous branch git checkout ${BRANCH} - git rebase --interactive master + git rebase --interactive ${PARENT} } -function grbr { +function grbroot { git rebase --interactive --autosquash --root } -function gam { - git autofixup master - git rebase --interactive --autosquash master -} - function ga { git autofixup HEAD~$1 git rebase --interactive --autosquash HEAD~$1 } +function gai { + # Save parent branch + PARENT=$(git_parent) + + echo "Rebasing with autofixup on" ${PARENT} + + git autofixup ${PARENT} + git rebase --interactive --autosquash ${PARENT} +} + # ╔═╗┬┌┬┐ ╔═╗┌┬┐┌─┐┌┐┌┌┬┐ # ║ ╦│ │ ╠═╣│││├┤ │││ ││ # ╚═╝┴ ┴ ╩ ╩┴ ┴└─┘┘└┘─┴┘