1

I am a git newbie. Please bare me if my question is silly. I created a repository nameed "testrepo" in github.com (GUI) and added a readme file.(committed).

if i issue this command "git clone https://github.com/username/testrepo.git" from my local desktop machine, it creates a new repository in the same name (testrepo) with all the content. (readme file). I understood this. As the name says, it is exactly cloning the remote repository (not cloning a branch in a repo) into local machine.

My question is i created a local repository named "testrepo2" by issuing a command "git init testrepo2". I added some files and i committed the changes.

Now thru some command i want to export this entire repository (testrepo2) to my github.com account. To be precise i dont want to create a repository manually in github.com and push the local changes to that. I want to push the entire local repo to the remote. Please help me. Thanks in advance.

Saravana Kumar M
  • 460
  • 9
  • 19
  • this is most probably a duplicate of this question: http://stackoverflow.com/questions/2423777/is-it-possible-to-create-a-remote-repo-on-github-from-the-cli-without-ssh – glaed Mar 06 '15 at 13:11
  • @Saravana, did my answer work for you? – PJ Bergeron Mar 07 '15 at 06:38

2 Answers2

1

You can create a Github repo from the command line using their API.

Please try:

curl -u 'USERNAME' https://api.github.com/user/repos -d '{"name":"testrepo2"}' #Replace USERNAME by your Github username

git remote add origin https://github.com/username/testrepo2.git #to add the remote
git push origin master #to push your commits

Please see: https://developer.github.com/v3/repos/#create

PJ Bergeron
  • 2,788
  • 4
  • 25
  • 42
  • Hey, I am sorry. What u suggested is adding the new files into the existing testrepo repository. thats not what i want. I want to a new repository to be created in github,com with the name testrepo2. – Saravana Kumar M Mar 06 '15 at 13:04
  • So your question is how to create a github repo from the command line? – PJ Bergeron Mar 06 '15 at 13:06
0

If I understand correctly, you want to know, how you can add a repository to your Github-account completely from the command line. As far as I know, you can't. At least not without additional tools like the Github API.

The Github help pages address the issue of adding a (locally) existing repository to your account here. The first step is always to create a repository via the web interface.

When you have created an empty repository on GitHub and a existing repo with some commits locally, you can push your work with the following commands:

git remote add origin https://github.com/myUserName/testrepo2.git
git push origin master

This adds your Github-repo as the new remote named 'origin'.

glaed
  • 431
  • 1
  • 7
  • 19