5

Assume I have a local folder called Test and I want that as a repo on github. Is there a way to do this purely using the terminal i.e without opening github, manually create a repo and push it to that?

Something like

git init
git add ReadMe.txt
git commit -m"initial commit"
git <create repo with this git account>
git <push to the created repo above> 

such that there now on my github user is a repo with the name Test containing the ReadMe.txt

(I have added the SSH key)

CutePoison
  • 4,679
  • 5
  • 28
  • 63

2 Answers2

6

You must do something on GitHub, to create the repository there. This can be as simple as telling GitHub "create an empty repository under my GitHub account", but there's no Git command to do this: GitHub require you to access some web on their site, set some parameters, and send a request.

You can do this through the curl program, if you have that installed. See, e.g., https://gist.github.com/btoone/2288960. If you don't have curl installed, most modern programming languages have packaged routines for doing web operations (e.g., Python's requests library), but it will usually take at least a few lines of code.

Once the GitHub-side repository exists—you can create this at any point, before or after doing command-line commands to create and manipulate your local repository—it's just a matter of telling your local repository how to access the GitHub repository:

git remote add origin ssh://git@github.com/your-account/your-repo.git

for instance, assuming you'd like to use the standard name origin. Then:

git push origin master branch1 branch2

or:

git push --all origin

will send the appropriate commits and ask the Git repository at GitHub to set its branch name(s) as requested on the command line.

torek
  • 448,244
  • 59
  • 642
  • 775
1

GitHub is outside the scope of git itself, and there are no github specific commands in git.

However, there is hub "an extension to command-line git that helps you do everyday GitHub tasks without ever leaving the terminal". In particular, one such "everyday GitHub task" is hub create.

dxiv
  • 16,984
  • 2
  • 27
  • 49