I am having a problem when a double dash (–) is in a variable. In the grand scheme I want to have a variable that can handle any git option or combo of git options a user needs. The problem is when the variable is used to create the git command. If I manually put in --depth 1 instead of $CommandLineOptions the git command works fine in Powershell. But when I use the variable I get the error below. I have tried using `– and `-`-. I have also tried using other ways to run the git command like invoke-command etc… I know I’m missing something here with powershell and variables but I don’t know what.
Any help would be appreciated.
$RepoUri = "YourFavoritURL.git" $CommandLineOptions = "--depth 1" $GitCommand = "git clone $CommandLineOptions $RepoUri" write-output $GitCommand git clone $CommandLineOptions $RepoUri
PS F:\git-clone> .\doubledash.ps1
git clone --depth 1 YourFavoritURL.git
error: unknown option `depth 1’
usage: git clone [–]
-v, --verbose be more verbose
-q, --quiet be more quiet
--progress force progress reporting
-n, --no-checkout don't create a checkout
--bare create a bare repository
--mirror create a mirror repository (implies bare)
-l, --local to clone from a local repository
--no-hardlinks don't use local hardlinks, always copy
-s, --shared setup as shared repository
--recursive initialize submodules in the clone
--recurse-submodules initialize submodules in the clone
-j, --jobs number of submodules cloned in parallel
--template
directory from which templates will be used
--reference reference repository
--dissociate use --reference only while cloning
-o, --origin use instead of 'origin' to track upstream
-b, --branch
checkout instead of the remote's HEAD
-u, --upload-pack
path to git-upload-pack on the remote
--depth create a shallow clone of that depth
--single-branch clone only one branch, HEAD or --branch
--shallow-submodules any cloned submodules will be shallow
--separate-git-dir
separate git dir from working tree
-c, --config
set config inside the new repository
-4, --ipv4 use IPv4 addresses only
-6, --ipv6 use IPv6 addresses only</em>