Reputation: 30
I know I can alias commands in git, but my branch name has some constant prefix, so can I alias this prefix?
Like this:
Branch name: bugfix_0000_00000000
I want to alias the bugfix_0000
into bug
so I can check out this branch by git checkout bug_00000000
.
Here is what I tried:
bugfix_0000
into bug
, but not work for me.git checkout
to gck
, butgck bug_00000000
does not work.Upvotes: 0
Views: 220
Reputation: 3874
As far as I know, aliases can only be defined for commands, not for parameters.
What you could do (assuming *nix) is to create a simple one-line script called e.g. git-cobug
(CheckOut BUG) and store it somewhere reachable from your $PATH
:
#!/bin/bash
git checkout bugfix_0000_$1
Then you could use it like: git cobug 00000000
in order to checkout bugfix_0000_00000000
branch.
Another suitable thing you could do (assuming Bash shell) which might remove the need for such an alias is to setup your git for tab-completion, as described in Git Manual - Tips and Tricks:
Download the file https://github.com/git/git/blob/master/contrib/completion/git-completion.bash and source it from your .bashrc file.
This way, you can type git checkout bu
and then press tab, and the shell will auto-complete it
to bugfix_0000_0000000
(so you only have to type the remaining 1, 2 or 3) if the only branches you have which start with bu
are bugfix_0000_00000001
, bugfix_0000_00000002
, and bugfix_0000_00000003
.
Upvotes: 0
Reputation: 30956
If you are using git bash for windows, in the bash shell run
echo export bug="bugfix_0000" >> ~/.bash_profile
and then
source ~/.bash_profile
or reopen the shell.
Now you can use ${bug}
in commands where bugfix_0000
is needed.
git checkout ${bug}_000000
If you are using Ubuntu, you could add the export in ~/.bashrc
. For other systems, there is a similar file.
Upvotes: 1