无法将文件推送到远程存储库

Cannot push files to remote repository

我为我受邀参加的项目克隆了一个空 repo,但无法将文件推送到远程(第一次推送)。

git remote -v
origin  https://gitlab.com/project-path (fetch)
origin  https://gitlab.com/project-path (push)

我可以确认我已成功添加 ssh public 密钥:

ssh -T git@gitlab.com
Welcome to GilLab, @username!

但是无法推送文件:

git push README.md
fatal: invalid gitfile format: README.md
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

我在这里错过了什么?

您不能将文件推送到远程分支。 git push 在分支上操作。

这是一个简单的工作流程。

# modify the README.md file, or any other file

# add it and make a commit
git add REAME.md
git commit -m "update README"

# push the branch to remote, replace "<remote-repo>" with real repo name
git push <remote-repo> <branch>
# or
git push <remote-repo> <local-branch>:<remote-branch>
# eg
git push origin master

顺便说一句,在这种情况下,您的 ssh public 密钥不会在 git push 中使用。因为 "remote" 分支 origin 使用 https 协议,而不是 git 协议。