git GIT第一次推新项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11581255/
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
GIT pushing a new project for the first time
提问by stef
I have a project on my local machine I've been working on alone, that I'd like to push to a remote server (running ubuntu & gitosis)
我在本地机器上有一个我一直在单独工作的项目,我想将其推送到远程服务器(运行 ubuntu 和 gitosis)
On the remote server I did
在我做的远程服务器上
git init
Initialized empty Git repository in /home/stefan/.git/
Locally git status
says
当地git status
说
git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .DS_Store
# .travis.yml
# license.txt
# nbproject/
# bla/.DS_Store
# bla/cache/
nothing added to commit but untracked files present (use "git add" to track)
I have also done
我也做过
git remote add origin [email protected]:psdemo.git
Now: when I try to push, the following happens
现在:当我尝试推送时,会发生以下情况
git push origin master
fatal: 'psdemo.git' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
It makes sense in a way since I just have an empty git repo.
这在某种程度上是有道理的,因为我只有一个空的 git 存储库。
How can I push my files to this remote server? I guess what I need is cloning from my local machine to the remote machine, somehow?
如何将我的文件推送到此远程服务器?我想我需要的是从我的本地机器克隆到远程机器,不知何故?
采纳答案by Aldo Stracquadanio
The string
字符串
[email protected]:psdemo.git
[email protected]:psdemo.git
should be a valid ssh path. As far as I see in the previous line:
应该是有效的 ssh 路径。据我在上一行中看到:
git init Initialized empty Git repository in /home/stefan/.git/
git init Initialized empty Git repository in /home/stefan/.git/
You created a repository in /home/stefan/ so I would expect something like:
您在 /home/stefan/ 中创建了一个存储库,所以我希望是这样的:
[email protected]:~
But probably it isn't what you want. You should create a folder psdemo.git
in your home in the remote server. For this, do a
但可能这不是你想要的。您应该psdemo.git
在远程服务器的家中创建一个文件夹。为此,做一个
git init --bare ~/psdemo.git
In that and then add the remote with:
在那个然后添加遥控器:
[email protected]:~/psdemo.git
Then you should be able to push!
那你应该可以推了!
回答by Sergey K.
You cannot push an empty project to the upstream. You have to add some files via git add
and them commit them locally using git commit
. Only after that you can push your changes into the upstream.
您不能将空项目推送到上游。您必须通过添加一些文件,git add
然后他们使用git commit
. 只有在那之后,您才能将更改推送到上游。
Ensure the remote repository can accept commits.
确保远程存储库可以接受提交。
回答by twalberg
By this:
这样:
Initialized empty Git repository in /home/stefan/.git/
在 /home/stefan/.git/ 中初始化空的 Git 存储库
it looks like you initialized your home directory on the remote server as a repository.
看起来您将远程服务器上的主目录初始化为存储库。
But this:
但是这个:
git remote add origin [email protected]:psdemo.git
git remote add origin [email protected]:psdemo.git
is adding your ${HOME}/psdemo.git
as the remote URL. This does not match, which is why you get the error.
正在添加您${HOME}/psdemo.git
作为远程 URL。这不匹配,这就是您收到错误的原因。
Try git init /home/stefan/psdemo.git
on the remote.
试试git init /home/stefan/psdemo.git
遥控器。
回答by sobering
The path to your remote repository may be incomplete. Instead of psdemo.git
, try something like /home/stefan/.git/
and give it another try.
远程存储库的路径可能不完整。而不是psdemo.git
,尝试类似的东西/home/stefan/.git/
,然后再试一次。
回答by Piotr Kalinowski
Looking at the Initialized empty Git repository in /home/stefan/.git/
part, your remote repo is not psdemo.git, but rather /home/stefan (or maybe /home/stefan/.git would work).
看看这Initialized empty Git repository in /home/stefan/.git/
部分,你的远程仓库不是 psdemo.git,而是 /home/stefan(或者 /home/stefan/.git 可以工作)。
BTW: you usually use bare repositories on remotes (git init --bare
), so that they don't have a working copy there.
顺便说一句:您通常在遥控器 ( git init --bare
)上使用裸存储库,因此它们在那里没有工作副本。