gpt4 book ai didi

git 推送到 GitHub 存储库分支给出错误 "src refspec master does not match any"

转载 作者:太空狗 更新时间:2023-10-29 13:25:46 27 4
gpt4 key购买 nike

我 fork 了 Flask 存储库并从 GitHub 克隆了它的网站分支

git clone --recursive https://github.com/lovesh/flask.git -b website

然后我像这样配置了远程

git remote add upstream https://github.com/lovesh/flask.git -t website
git fetch upstream

然后我进行了更改(我没有创建任何其他文件但修改了 2 个文件)我必须进行然后添加文件并提交这样的更改

git add .
git commit .

这提示我对提交发表评论,然后我输入了评论。现在它向我展示了

2 files changed, 69 insertions(+), 7 deletions(-)

但是当我尝试将这些更改推送到我的 GitHub 帐户时

git push origin master

显示错误

error: src refspec master does not match any.
error: failed to push some refs to 'https://github.com/lovesh/flask.git'

我环顾四周,遇到这个问题的人说他们没有提交更改 herehere .但是即使那时我也确实提交了它向我显示了这个错误。确认我尝试过

git status 

它显示

# On branch website
# Your branch is ahead of 'origin/website' by 1 commit.
#
nothing to commit (working directory clean)

另外 git log 也会在日志中显示我的提交。我是 git 的新手。我错过了什么吗?

最佳答案

首先,在克隆你的 repo 后你没有主分支。
git clone 详情:

--branch <name>
-b <name>

Instead of pointing the newly created HEAD to the branch pointed to by the cloned repository's HEAD, point to <name> branch instead.
In a non-bare repository, this is the branch that will be checked out.
--branch can also take tags and detaches the HEAD at that commit in the resulting repository.

因此,在您的情况下,如果您想创建本地网站分支并将其跟踪到原点,您需要:

git push -u origin website

(之后,一个简单的 git push 就足够了:更多关于“git - push current vs. push upstream (tracking) ”中的推送策略)


你的另一个 Remote ' upstream ' 也只会跟踪 upstream/website分支:

git remote 文档确实提到:

With -t <branch> option, instead of the default glob refspec for the remote to track all branches under the refs/remotes/<name>/ namespace, a refspec to track only <branch> is created.
You can give more than one -t <branch> to track multiple branches without grabbing all branches.

在您的情况下,您只跟踪 upstream/website ( +refs/heads/website:refs/remotes/upstream/website ) 而不是 default refspec (+refs/heads/*:refs/remotes/upstream/*)。

关于git 推送到 GitHub 存储库分支给出错误 "src refspec master does not match any",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14057870/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com