从本地文件夹创建远程 git repo

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14087667/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 07:57:12  来源:igfitidea点击:

Create a remote git repo from local folder

git

提问by pguardiario

I think there must be an easier way to do this. Right now I find myself following these steps:

我认为必须有一种更简单的方法来做到这一点。现在我发现自己遵循以下步骤:

On the remote:

在遥控器上:

mkdir my_repo
cd my_repo
git init --bare

Then locally:

然后在本地:

mv my_repo old_my_repo
git clone ssh://myserver/my_repo
mv old_my_repo/* my_repo
rmdir old_my_repo
cd my_repo
git add .
git commit -m 'foo'
git push origin master

Is there some shortcut?

有什么捷径吗?

回答by Gabriele Petronella

Unfortunately almost all steps are necessary, even though locally you can avoid to recreate the repo by cloning it.

不幸的是,几乎所有步骤都是必需的,即使在本地您可以通过克隆它来避免重新创建存储库。

Just init the repo and add a remote

只需初始化 repo 并添加一个遥控器

cd my_repo
git init
git remote add origin ssh://myserver/my_repo
git add .
git commit -m "Initial commit"
git push -u origin master

Note that the -uoption will add a tracking reference, so later on you can simply type git pushinstead of git push origin master.

请注意,该-u选项将添加跟踪引用,因此稍后您只需键入git push而不是git push origin master.

回答by Doug Park

The answer from Gabriele almost worked for me.

Gabriele 的回答几乎对我有用。

Before the git push -u origin mastera git init --bare my_reponeeds to be called in the directory that ssh:://myserverpoints to.

git push -u origin masteragit init --bare my_repo需要在ssh:://myserver指向的目录中调用之前。