1

I have generated and added my SSH key into Github.

Now I'm trying to write a script which generates a new private repository in Github and upload intiial files. User will be prompted for the name of the new repository.

The code that I have is given below. The problem is that when trying to push files into Github I get the following error

ssh: Could not resolve hostname github.com:rongardF: Name or service not known
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Why do I get this error? Is there anything else that I have to do?

The code:

@echo off
set /p name="Enter new project name: "

touch README.md
touch .gitignore
echo __Previews>>.gitignore
echo History>>.gitignore
echo Project Outputs *>>.gitignore
echo * Logs *>>.gitignore

git config --global user.email "r****[email protected]"
git config --global user.name "R** F****"

curl -u r***F:p*****d https://api.github.com/user/repos -d "{\"name\":\"%name%\",\"private\":true}"

git init
git add .
git commit -m "Initial commit"
git remote add origin [email protected]:r***F/%name%.git
git push -u origin master

NB: The names obviously don't include "*" symbol, this is just for blurring out my details.

rongard
  • 89
  • 7

2 Answers2

0
git remote add origin [email protected]:r***F/%name%.git

For testing, you can check if this syntax would work in your case

git remote add origin ssh://[email protected]/r***F/%name%.git

Check also if a simple ssh -Tv [email protected] works (meaning if it display a Welcome message at the end)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

Thanks for the suggestion @VonC

I got it to work by adding the following line before the push command:

git remote set-url origin https://github.com/r****F/%name%.git

Not sure why, but this works. So the snippet of the final code is:

...
...
git init
git add .
git commit -m "Initial commit"
git remote add origin [email protected]:r****dF/%name%.git
git remote set-url origin https://github.com/r****F/%name%.git
git push -u origin master
rongard
  • 89
  • 7