Robert Cooper
Robert Cooper

Reputation: 2250

Git rebase ZSH shell alias

I picked up a git alias online that is supposed to be the command git rebase -i HEAD~$1 where $1 is a number passed to the alias. Here is the git alias I've got setup in my .zshrc file:

alias grn="! sh -c \"git rebase -i HEAD~$1\" -"

Example usage from the terminal:

$ grn 3 // This should translate to git rebase -i HEAD~3

The issue i'm running into is that the passed integer argument (e.g. 3), is not being passed to my alias so the git alias is effectively always running git rebase -i HEAD~.

Any clues on how to fix this alias?

Upvotes: 0

Views: 771

Answers (2)

phd
phd

Reputation: 94696

Shell alias with parameters is impossible, but git alias is definitely possible. Either

git config alias.grn '! sh -c "git rebase -i HEAD~$1" -'

or

git config alias.grn '!f() { git rebase -i HEAD~$1; }; f'

Run as git grn 3.

Upvotes: 4

dmadic
dmadic

Reputation: 477

Refering to this question I would say having an alias which takes parameters is not possible.

You could easily do it with single-line function though.

Just put:

grn() { git rebase -i HEAD~"$1"; } 

in .zshrc and you can run it the same way as an alias.

Upvotes: 1

Related Questions