我可以克隆 repo 和 pull,但我不能 push

I can clone repo and pull, but I can't push

我正在尝试将更改推送到远程存储库,但出于某种原因我不能。

当我 git branch 这是我看到的:

develop
feature/all_features
* feature/Tommaso

当我 git status:

On branch feature/Tommaso
nothing to commit, working directory clean

我可以 clone 回购和 pull 开发,但是当我这样做时 git pull 这就是我得到的:

There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> feature/Tommaso

我猜问题是远程仓库没有我在本地创建的当前分支。

编辑: 我不够清楚:我想在 feature/allfeatures 中创建分支 feature/Tommaso 。我是为那些可能认为我正在尝试创建 develop

分支的人说的

是吗?我该如何解决?

如果您需要其他信息来解决问题,请告诉我。提前谢谢你

I guess the problem is that the remote repo does not have the current branch I created locally

我也觉得是这个问题。首先,push 带有 -u 标志的当前分支(设置上游),然后尝试 git pull.

$ git push -u origin HEAD

N.B: -u = --set-upstream 告诉 Git 记住参数,这样下次我们可以简单地 运行 git pullgit push.

当您 运行 仅 git pull 而未提及分支名称时,git 会尝试从跟踪远程分支中拉取。

$ git pull

如果你想拉另一个远程分支,那么只需提到分支名称。

$ git pull origin <branch-name>

如果您想要 feature/allfeatures 的新分支 feature/Tommaso,请遵循:

$ git checkout feature/allfeatures
$ git checkout -b feature/Tommaso
$ git push origin HEAD

现在,feature/allfeaturesfeature/Tommaso 具有相同的 changes/commits。

尝试以下命令。

$ git pull origin <branch_name>

$ git push origin HEAD:refs/for/<branch_name>

如果您想创建自己的集成分支。

$ git checkout -b <integration branch name> origin/<origin branch name>

$ git push origin <integration branch name>

如果您正在使用分支,那么您必须与远程保持相同的分支以保持一致。假设如果您在远程仓库上有一个名为 foo 的分支,那么您还必须在本地保留一个名为 foo 的分支。

你是怎么做到的。假设你的本地仓库中没有名为 foo 的分支,所以你这样做

$ git fetch

它会将远程所有分支的信息获取到你的本地,从这个命令的输出中可以清楚地看到。

然后你做一个git branch看看有哪些分支可用。现在您将能够在本地看到分支 foo。执行 git checkout -b foo 这会将您的分支切换到 foo。使用 git log 查看你有最新的分支,远程 else do git pull origin foo。现在您可以使用 git push origin foo

您评论中提到的日志表明您正在尝试从不同的分支中提取并与本地存储库中的其他分支合作。在开始工作之前切换分支,否则你将 运行 合并冲突并弄乱 repo

正如其他人所说,没有名为

的分支

使用此代码

git push origin <your branch name>

已编辑

你已经做到了吗?

git remote set-url origin https://github.com/MyRepo/project.git

如果您对 repo 有读权限但没有写权限,您可能会遇到这种情况。