git status中没有提到原点,但是有push和fetch工作

roejwanj  于 2023-03-06  发布在  Git
关注(0)|答案(1)|浏览(101)

我在gitlab.com上有一个本地git仓库和一个远程仓库。与另一个类似的情况相反,命令git status不输出任何关于源的信息。
git status -uno的输出(有很多未跟踪的文件,所以我跳过它们)

On branch master
nothing to commit (use -u to show untracked files)

我们在其他地方

On branch master
Your branch is up to date with 'origin/master'.

你知道如何得到预期的行为(第二个)吗?
我怀疑可能是两次设置原点的结果。在初始化过程中,我设置了

$ git push --set-upstream https://gitlab.com/<username>/projectA.git
$ git push --set-upstream https://gitlab.com/<username>/projectB.git
$ git remote add origin https://gitlab.com/<username>/projectB.git

我删除原点,然后重新设置:

$ git remote rm origin
$ git push --set-upstream https://gitlab.com/<username>/projectB.git
$ git remote add origin https://gitlab.com/<username>/projectB.git

我通过git remote -v测试了原点的样子,删除原点后什么也没显示,每隔一段时间的结果是(现在是):

origin  https://gitlab.com/<username>/projectB.git (fetch)
origin  https://gitlab.com/<username>/projectB.git (push)

git fetch以我所知道的其他方式运行。它返回

$ git fetch -v
POST git-upload-pack (102 bytes)
From https://gitlab.com/<username>/projectB
 * branch            master     -> FETCH_HEAD

在标准情况下

$ git fetch -v
POST git-upload-pack (155 bytes)
From https://gitlab.com/<username>/projectC
 = [up to date]      main       -> origin/main

为了完整性,我在某个时刻做了git gcgit prune,这是我第一次做的事情,所以我没有经验,如果它有一些副作用有关这个问题。

toe95027

toe950271#

  • 要“修复”您的问题:*

一旦定义了一个命名的远程(在您的问题中:origin),并提取其分支,则可以:

git branch -u origin/main

你需要使用named remotes来保持一个远程跟踪分支,当你使用显式的url时,git将不会存储它在本地获取的分支(或者你通过运行git push更新的分支),所以你会发现自己没有任何东西可以指向,即使指定了--set-upstream
如果您经常需要从两个不同的遥控器推送或拉取,请为它们指定不同的名称:

# for example :
git remote add origin https://gitlab.com/<username>/projectB.git
git remote add upstream https://gitlab.com/<username>/projectA.git

相关问题