Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git clone from bash script

I am trying to automate my interactions with Git building a script and I am having the following problem.

This works from the command line:

git clone [email protected]:blablabla/reponame.git /Users/myname/dev/myfolder

And now I would like to do the same, but from my script. I have the following:

#/bin/bash

repository="[email protected]:blablabla/reponame.git"

localFolder="/Users/myname/dev/myfolder"

git clone $repository" "$localFolder

that gives me this error

GitHub SSH access is temporarily unavailable (0x09). fatal: The remote end hung up unexpectedly

Any light on this will be much appreciated

like image 304
agatha Avatar asked Jun 01 '12 20:06

agatha


People also ask

How do I clone a GitHub repository bash?

On GitHub.com, navigate to the main page of the repository. Above the list of files, click Code. Click Open with GitHub Desktop to clone and open the repository with GitHub Desktop. Follow the prompts in GitHub Desktop to complete the clone.

How do I clone a specific branch in git bash?

You can clone a specific branch from a Git repository using the git clone –single-branch –branch command. This command retrieves all the files and metadata associated with one branch. To retrieve other branches, you'll need to fetch them later on.


1 Answers

You mean git clone "$repository" "$localFolder", I'd hope?

Running git clone $repository" "$localFolder is something quite different:

  • Because neither variable is within double quotes, their contents are string-split and glob-expanded; thus, if they contained whitespace (generally, characters within $IFS), they could become multiple arguments, and if they contained globs (*, [...], etc), those arguments could be replaced with filenames (or simply removed from the generated argument list, if the nullglob shell option is enabled)
  • Because the space between the two arguments is quoted, they are combined into a single argument before being passed to git.

So, for the values you gave, what this script runs would be:

git clone "[email protected]:blablabla/reponame.git /Users/myname/dev/myfolder"

...which is quite different from

git clone [email protected]:blablabla/reponame.git /Users/myname/dev/myfolder

...as it is giving the /Users/myname/dev/myfolder path as part of the URL.

like image 191
Charles Duffy Avatar answered Sep 21 '22 07:09

Charles Duffy