Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Multi Line Git Alias with a Function in ZSH

I'm trying to create a git alias to be able to call git resquash from foo branch (a child of master). The idea is to do a git rebase -i from the first commit in that branch without knowing the commit. Something is wrong though. I keep getting errors when trying it out.

Maybe my expansions are wrong? I'm using ZSH.

resquash = f() { CURRENTBRANCH=$(git symbolic-ref --short HEAD) ;\                      
                 COMMONCOMMIT=$(git merge-base ${CURRENTBRANCH} ${1-master}) ;\                      
                 git rebase -i $COMMONCOMMIT }; f
like image 964
adeluccar Avatar asked Jan 21 '26 03:01

adeluccar


1 Answers

You can split the alias over multiple lines if it is a string with line continuation. That is, quote it (with double-quotes) and use backslash characters at the line end (don't forget to escape other double-quote characters):

[alias]
    test = "!_(){ \
                echo \"Hello\"; \
                echo \"World\"; \
            };_"
like image 78
Parakleta Avatar answered Jan 23 '26 17:01

Parakleta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!