无法将文件推送到新创建的git仓库

che*_*eng 4 git git-push

也许是一个重复的问题,尽管我试图找出现有问题的答案但却失败了.

我用命令在服务器上创建了一个git repo:

mkdir gitrepo
cd gitrepo
git init
Run Code Online (Sandbox Code Playgroud)

然后从另一台机器我试图将文件推送到此repo但失败了.

git init
git clone user@server:~/gitrepo/.git
cd gitrepo
touch test
git add test
git commit -a
Run Code Online (Sandbox Code Playgroud)

现在使用,不会发生错误.当我尝试将更改推送到服务器时,会发生以下错误:

>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'
Run Code Online (Sandbox Code Playgroud)

有没有人遇到过这个问题?

我找到了一个博客,很好地解释了非裸机和裸机的区别.http://www.bitflop.com/document/111 遇到同样问题的人可以参考这个.

Ula*_*les 6

git push [remote-name] [branch-name].例如git push origin master


ell*_*eth 4

在第一台计算机上,您创建了一个非裸存储库或具有工作副本的存储库。推送到非裸仓库可能会有点令人兴奋,所以请确保这确实是您想要的。

在第二台计算机上,您在当前目录 ( git init) 中创建了一个新存储库,然后克隆gitrepo到一个子目录作为第二个存储库。再说一遍,没关系,只要确保它是您想要的即可。

以下是第一台机器上的裸存储库和第二台机器上的一个存储库的工作方式:

第一台机器:

git init --bare gitrepo.git
Run Code Online (Sandbox Code Playgroud)

第二台机器:

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
Run Code Online (Sandbox Code Playgroud)