-1

I have a script.sh that performs the "clone" operation of a git repository. Currently, the script works correctly with the target branch written in hard on the corresponding line.

/usr/bin/git clone https://my-url-repository --branch master --single-branch

If I replace "master" with "$1",

/usr/bin/git clone https://my-url-repository --branch $1 --single-branch

it can't complete the operation because it doesn't correctly take the branch and throws a fatal error.

warning: Could not find remote branch e to clone.
fatal: Remote branch e not found in upstream origin

However, if I print on screen the parameter $1 or ${1}, the entered value is displayed correctly.

#!/bin/bash

if [ -n "$1" ]; then
    echo Building from branch "["$1"]"
else
    echo "Please, enter branch name"
    exit
fi

Can you help me?

1 Answers1

0

I could not specifically solve the problem, but I did find an equally valid alternative. Instead of waiting for the parameter in the script call, within the same script I request the entry of the branch name, and then the clone is done without problems.

The code looks like this:

#!/bin/bash

echo "Please, enter branch name"
read branchName

And then I use the variable like this:

/usr/bin/git clone https://my-url-repository  --branch $branchName --single-branch