简体   繁体   English

将本地存储库克隆到github中

[英]Clone a local repository into github

I am a git newbie. 我是git新手。 Please bare me if my question is silly. 如果我的问题很傻,请裸露我。 I created a repository nameed "testrepo" in github.com (GUI) and added a readme file.(committed). 我在github.com(GUI)中创建了一个名为“ testrepo”的存储库,并添加了一个自述文件。(已提交)。

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. 如果我从本地台式机发出此命令“ git clone https://github.com/username/testrepo.git ”,它将使用所有内容以相同名称(testrepo)创建一个新存储库。 (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". 我的问题是我通过发出命令“ git init testrepo2”创建了一个名为“ 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. 现在,通过一些命令,我​​要将整个存储库(testrepo2)导出到我的github.com帐户。 To be precise i dont want to create a repository manually in github.com and push the local changes to that. 确切地说,我不想在github.com中手动创建存储库,并将本地更改推送到该存储库。 I want to push the entire local repo to the remote. 我想将整个本地存储库推送到远程。 Please help me. 请帮我。 Thanks in advance. 提前致谢。

You can create a Github repo from the command line using their API. 您可以使用他们的API从命令行创建Github存储库。

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 请参阅: https : //developer.github.com/v3/repos/#create

If I understand correctly, you want to know, how you can add a repository to your Github-account completely from the command line. 如果我理解正确,那么您想知道如何从命令行将存储库完全添加到您的Github帐户。 As far as I know, you can't. 据我所知,你做不到。 At least not without additional tools like the Github API . 至少不是没有Github API这样的附加工具。

The Github help pages address the issue of adding a (locally) existing repository to your account here . Github帮助页面在此处解决了向您的帐户添加(本地)现有存储库的问题。 The first step is always to create a repository via the web interface. 第一步始终是通过Web界面创建存储库。

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: 当您在GitHub上创建了一个空存储库并在本地创建了一个带有某些提交的现有存储库后,可以使用以下命令来推送您的工作:

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'. 这会将您的Github-repo添加为名为“ origin”的新遥控器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM