git新增遠端倉庫後不能push
漂亮男人
漂亮男人 2017-05-02 09:28:02
0
2
511

自己有一個阿里雲的ECS(CentOS7),需要把專案放到上面去,但不想通過github,想直接在本地git倉庫中添加遠端倉庫,直接push到ECS上。
在ECS中先建立了專案目錄,並且初始化了倉庫:$ git init
在本地倉庫中加入遠端倉庫:

$ git remote add ECSmaster ssh://username@IP/~/path/.git

添加好之後卻不能push,錯誤訊息如下:

$ git push -u ECSmaster master
username@IP's password:
Counting objects: 180, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (75/75), done.
Writing objects: 100% (180/180), 32.15 KiB | 0 bytes/s, done.
Total 180 (delta 104), reused 180 (delta 104)
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To ssh://username@IP/~/cloudNote/.git
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'ssh://username@IP/~/cloudNote/.git'


$ git remote show ECSmaster
username@IP's password:
* remote ECSmaster
  Fetch URL: ssh://username@IP/~/cloudNote/.git
  Push  URL: ssh://username@IP/~/cloudNote/.git
  HEAD branch: (unknown)

以上操作參考的是這篇文章:http://www.cnblogs.com/xiaoya901109/archive/2012/08/03/2620664.html

漂亮男人
漂亮男人

全部回覆(2)
过去多啦不再A梦

伺服器上初始化倉庫時應該加上--bare參數
git init --bare

为情所困

遠端伺服器輸入以下:
git config 'receive.denyCurrentBranch' warn

這種錯誤是出於git的一種保護措施 master->master 怕誤操作

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板