Pergunta

I am trying to write a quick alias to checkout and track a remote branch with this syntax

git get {branch_name}

the correct method to do this would be

git checkout --track origin/{branch_name}

I tried

[alias]
   get = "!sh -c 'git checkout --track origin/$1'"

But get a fatal: missing branch name

What am I missing?

Foi útil?

Solução 2

your code looks like it's a shell alias (i see $1 substitutions and the sh command). i would suggest adding it as an alias in your .gitconfig file. in that file the "git" command is understood.

[alias]
    get = 'checkout --track origin/'

(you might need a double slash, escaping and all, not 100% on that)

so calling:

$ git get someName

will essentially call:

git checkout --track origin/someName

Outras dicas

Add the following alias to your .gitconfig file

cto = "!f() { \
    git checkout --track origin/\"$1\"; \
}; f"

I use cto (checkout track origin) for alias name and shell command with substitutions to pass in branch name.

You can then use the alias like so

git cto my-cool-branch

which will be equivlant to

git checkout --track origin/my-cool-branch

I think it's already trying to substitute $1. Another thing that could be cause of trouble the sh command in a git alias config. I would use a shell alias instead.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top