2

I just recently discovered how to make git aliases, which are great, but I was wondering if there is a way to include my common branch prefix with the alias. So what I would like is something like:

Alias in .gitconfig:

[alias]
    br = checkout -b branchfolder/

and then beeing able to use the command like

$ git br newbranch

to call

git checkout -b branchfolder/newbranch

This, of course, is not what happens, as the command translates to

git checkout -b branchfolder/ newbranch

and I get an error where git asking:

fatal: Cannot update paths and switch to branch 'branchfolder/' at the same time. Did you intend to checkout 'newbranch' which can not be resolved as commit?

How would I achieve what I want?

jonasfh
  • 4,151
  • 2
  • 21
  • 37

1 Answers1

1
[alias]
    br = "!sh -c 'git checkout -b branchfolder/$0'"

I would advise you to use -t instead of -b though.

Knu
  • 14,806
  • 5
  • 56
  • 89