0

I've created an alias in my .bash_profile

alias gco="git checkout origin/${1}"

but whenever I try to call a command like this:

gco master

it responds with:

error: pathspec 'origin/' did not match any file(s) known to git.
error: pathspec 'master' did not match any file(s) known to git.

Could anyone help me understand why its returning these errors and not just concatenating the text properly? Thanks!

ForgetfulFellow
  • 2,477
  • 2
  • 22
  • 33
  • Aliases can't take arguments. See this post: [Make a Bash alias that takes a parameter](http://stackoverflow.com/questions/7131670/make-a-bash-alias-that-takes-parameter) – codeforester Mar 01 '17 at 19:31
  • The issue is that $@ can be used, but it will create a single space. So it would print `origin/ master`. It would work if you just want "git checkout master", that would be `alias gco="git checkout $@"`. But if you want it with the /, you'll need to make a function. The link @codeforester gave should help you. – rowan Mar 01 '17 at 23:47
  • I don't understand why everyone is saying alias's can't take arguments as the error clearly shows the argument taken in (although I'm a bash noob and am mostly likely wrong about the terminology). Anyways, @rowan thanks for the explanation, that makes sense. If you wrote that as an answer I would accept it :) – ForgetfulFellow Mar 01 '17 at 23:57
  • You're welcome @ForgetfulFellow, want me to write you the function as an example? – rowan Mar 02 '17 at 00:04
  • I'm good, I think i wrote something that works. Thanks though! – ForgetfulFellow Mar 02 '17 at 03:53

0 Answers0