无法将文件推送到新创建的 git repo
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10740378/
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
Failed to pushing files into newly created git repo
提问by cheng
Maybe a duplicate question, though I have tried to found out answers from existing questions but failed.
也许是一个重复的问题,尽管我试图从现有问题中找出答案但失败了。
I created a git repo on the server with command:
我使用以下命令在服务器上创建了一个 git repo:
mkdir gitrepo
cd gitrepo
git init
Then from another machine I tried to push files to this repo but failed.
然后从另一台机器我试图将文件推送到这个 repo 但失败了。
git init
git clone user@server:~/gitrepo/.git
cd gitrepo
touch test
git add test
git commit -a
Util now, no error occurs. When I try to push the changes to the server, the following error occurs:
现在使用,没有错误发生。当我尝试将更改推送到服务器时,出现以下错误:
>git push
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'user@server:~/gitrepo/.git'
Anyone encountered this problem before?
以前有人遇到过这个问题吗?
I found an blog which explains well the difference between non-bare and bare repo. http://www.bitflop.com/document/111Those who gets the same problem may refer to this.
我找到了一个博客,它很好地解释了非裸和裸 repo 之间的区别。http://www.bitflop.com/document/111遇到同样问题的可以参考这个。
采纳答案by ellotheth
On the first machine, you created a non-bare repository, or a repository that has a working copy. Pushing to a non-bare repo can get a little exciting, so make sure that's actually what you want.
在第一台机器上,您创建了一个非裸存储库,或一个具有工作副本的存储库。推送到非裸存储库可能会有点令人兴奋,因此请确保这确实是您想要的。
On the second machine, you created a new repository in the current directory (git init
), then cloned gitrepo
into a sub-directory as a second repo. Again, that's fine, just make sure it's what you wanted.
在第二台机器上,您在当前目录 ( git init
) 中创建了一个新存储库,然后将其克隆gitrepo
到子目录中作为第二个存储库。同样,这很好,只要确保它是你想要的。
Here's how it would work with a bare repo on the first machine and one repo on the second:
以下是第一台机器上的裸仓库和第二台机器上的一个仓库的工作方式:
First machine:
第一台机器:
git init --bare gitrepo.git
Second machine:
第二台机器:
git clone user@server:~/gitrepo.git
cd gitrepo
touch test
git add test
git commit -a
# '-u' tells git to track the remote master branch with your local master branch
git push -u origin master
回答by Ulas Keles
git push [remote-name] [branch-name]
. e.g. git push origin master
git push [remote-name] [branch-name]
. 例如git push origin master
回答by user3159604
refer to "Why can't I push to this bare repository?"
请参阅“为什么我不能推送到这个裸存储库?”
try doing: git push --set-upstream origin master
尝试做: git push --set-upstream origin master