背景

  • 在Gitlab创建了新仓库
  • 特意勾选了不用README初始化文件
  • 按照指引推送现有文件夹:
推送现有文件夹

cd existing_folder
git init --initial-branch=master
git remote add origin ssh://git@ssh.gitlab.lodatone.com:8022/deploy/reverse-proxies/hangzhou-erp2-infrastructure.git
git add .
git commit -m "Initial commit"
git push --set-upstream origin master
  • 报错
root@D218:/www/server/panel/vhost/nginx/erp2-infrastructure# git init --initial-branch=master
git remote add origin ssh://git@ssh.gitlab.lodatone.com:8022/deploy/reverse-proxies/hangzhou-erp2-infrastructure.git
git add .
git commit -m "Initial commit"
git push --set-upstream origin master
warning: re-init: ignored --initial-branch=master
Reinitialized existing Git repository in /www/server/panel/vhost/nginx/erp2-infrastructure/.git/
error: remote origin already exists.
On branch master

Initial commit

nothing to commit (create/copy files and use "git add" to track)
error: src refspec master does not match any
error: failed to push some refs to 'ssh://ssh.gitlab.lodatone.com:8022/deploy/reverse-proxies/hangzhou-erp2-infrastructure.git'

解决办法

echo "# hangzhou-erp2-infrastructure" > README.md

再次执行立即成功

root@D218:/www/server/panel/vhost/nginx/erp2-infrastructure# echo "# hangzhou-erp2-infrastructure" > README.md
root@D218:/www/server/panel/vhost/nginx/erp2-infrastructure# git init --initial-branch=master
git remote add origin ssh://git@ssh.gitlab.lodatone.com:8022/deploy/reverse-proxies/hangzhou-erp2-infrastructure.git
git add .
git commit -m "Initial commit"
git push --set-upstream origin master
warning: re-init: ignored --initial-branch=master
Reinitialized existing Git repository in /www/server/panel/vhost/nginx/erp2-infrastructure/.git/
error: remote origin already exists.
[master (root-commit) e2edbe7] Initial commit
 1 file changed, 1 insertion(+)
 create mode 100644 README.md
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 244 bytes | 244.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To ssh://ssh.gitlab.lodatone.com:8022/deploy/reverse-proxies/hangzhou-erp2-infrastructure.git
 * [new branch]      master -> master
branch 'master' set up to track 'origin/master'.
root@D218:/www/server/panel/vhost/nginx/erp2-infrastructure#