Search code examples
gitparameter-passingaliasgit-configgit-alias

How to properly use parameters in git aliases?


I have the following git alias in my .gitconfig file.

    clone-with-branches = "!cloneWithBranches() { \
        git clone $1 $2 ; \
    }; cloneWithBranches"

I am supposed to use it as follows:

git clone-with-branches folder1 folder2

(supposing that folder1 is valid working git repository that is accessible with its relative path)

when in command line I type,

git clone folder1 folder2

I indeed obtain a clone of folder1 in folder2 but when I used the alias:

git clone-with-branches folder1 folder2

I obtain an error

fatal: repository 'folder1' does not exist.

Can anyone tell me what I missed please?


Solution

  • Thanks Torek for the hint.
    I modified the script as below and then the alias woks perfectly.

        clone-with-branches = "!cloneWithBranches() { \
            git clone $GIT_PREFIX$1 $GIT_PREFIX$2 ; \
        }; cloneWithBranches"
    

    Please note that GIT_PREFIX is already set within Git and does not have to be set manually (cf http://schacon.github.io/git/git-config.html section alias.* )