microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.57k stars 29.02k forks source link

Git error (Cannot fast-forward to multiple branches.) when syncing during autofetch #158309

Open jeffrson opened 2 years ago

jeffrson commented 2 years ago

Does this issue occur when all extensions are disabled?: Yes

Steps to Reproduce:

In a folder with Git working copy with multiple branches and valid remote:

  1. git config --local --add pull.ff only
  2. in VSCode settings "git.autofetch": true and, maybe "git.confirmSync": false, "git.autofetchPeriod": 10 (to increase chances)
  3. click git sync in status bar, a couple of times
[2022-08-16T18:25:45.833Z] > git fetch [1557ms]
[2022-08-16T18:25:45.874Z] > git status -z -uall [38ms]
[2022-08-16T18:25:45.907Z] > git symbolic-ref --short HEAD [31ms]
[2022-08-16T18:25:45.943Z] > git for-each-ref --format=%(refname)%00%(upstream:short)%00%(objectname)%00%(upstream:track)%00%(upstream:remotename)%00%(upstream:remoteref) refs/heads/develop refs/remotes/develop [33ms]
[2022-08-16T18:25:45.979Z] > git remote --verbose [31ms]
[2022-08-16T18:25:45.980Z] > git for-each-ref --sort -committerdate --format %(refname) %(objectname) %(*objectname) [35ms]
[2022-08-16T18:25:46.014Z] > git config --get commit.template [31ms]
[2022-08-16T18:25:46.640Z] > git pull --tags origin develop [1606ms]
[2022-08-16T18:25:46.640Z] From ...
 * branch            develop    -> FETCH_HEAD
fatal: Cannot fast-forward to multiple branches.

Apparently, git fetch can run during sync (or the other way around). If this occurs, there might be an error, requesting to open Git log, which contains "Cannot fast-forward to multiple branches".

legioz commented 2 years ago

I have the same problem on Linux using version 1.71.2 74b1f979648cc44d385a2286793c226e611f59e7 x64

movy commented 1 year ago

Just encountered this in two separate repos one after another, very cryptic error, thanks for this issue.

starball5 commented 1 year ago

Possibly related Stack Overflow question: What is causing "Cannot fast-forward to multiple branches" during git pull?

voneiden commented 1 year ago

Possibly related Stack Overflow question: What is causing "Cannot fast-forward to multiple branches" during git pull?

Yes, very much related root cause.

Namstel commented 1 year ago

I'm also getting this when I type git pull in the terminal within VSCode. But when I then type cd .. and cd <repo> and try git pull again, it works as expected.

Neal commented 1 year ago

It should probably also work if you wait a couple seconds and try again to avoid any concurrent fetch so the cd shouldn’t really be required I believe. On Jul 13, 2023 at 02:45 -0700, Niels van Amstel @.***>, wrote:

I'm also getting this when I type git pull in the terminal within VSCode. But when I then type cd .. and cd and try git pull again, it works as expected. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>

joulev commented 1 year ago

I also encountered this error, but it's really hard to reproduce since it seems to just appear randomly. Just now I also saw this error, but without changing anything, after a few seconds it worked again.

xmedeko commented 11 months ago

VS Code should use git fetch --no-write-fetch-head to do autofetch.

starball5 commented 11 months ago

@xmedeko what do you mean "shall"? Did you make a PR? Or did you mean to say "should"?

xmedeko commented 11 months ago

@starball5 I meant to say "should". I've fixed the comment. (Apologies, not a native English speaker.)

eldarj commented 10 months ago

I stumbled upon this even though I am not using vscode, just plain git in a terminal. Any ideas? @starball5

starball5 commented 10 months ago

I stumbled upon this even though I am not using vscode, just plain git in a terminal. Any ideas? @starball5

I told you on SO already. If your problem has nothing to do with VS Code, you're in the wrong place asking about it here.

juwitt commented 10 months ago

Probably trivial, but ftr: I just encountered the same error when I had not yet pushed a commit on device A with my GitHub login and tried to pull on device B with the same login. Pushing on device A solved the problem for me.

jonparker commented 4 months ago

Just encountered the same error

  1. git pull

Response:

fatal: Cannot fast-forward to multiple branches.
  1. git status

Response:

Your branch is behind 'origin/branch-name' by 5 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

nothing to commit, working tree clean
  1. git pull

Response:

Updating 96f179ca..369254d7
Fast-forward
...
 3 files changed, 216 insertions(+), 156 deletions(-)

I am using a VSCode terminal. This was the first command I ran in VSCode today. Maybe it's a network timeout issue.