Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is causing "Cannot fast-forward to multiple branches" during `git pull` in VS Code?

We use the default workflow on GitHub, i.e., create a feature branch, push some commits to it, merge to master. Nothing fancy.

In the master branch, I only ever pull newer changes from GitHub, never push. In visual terms, the "down" direction in VS Code typically contains some commits while the "up" direction doesn't:

Now, from time to time (not always!), invoking the sync in VS Code which is git pull origin master ends up with this error:

> git pull origin master
From https://github.com/shoptet/sofa
 * branch                master     -> FETCH_HEAD
fatal: Cannot fast-forward to multiple branches.

What does the error mean? I don't see any multiple branches.

It's important to note that after I run the operation again, it works. So my workflow usually is:

  1. Click the "sync" button in VS Code (runs git pull origin master)
  2. See the "Cannot fast-forward to multiple branches" error, dismiss it.
  3. Click the "sync" button again, see it succeed.

A bit annoying.

BTW my repo is in a clean state:

$ git status
On branch master
Your branch is behind 'origin/master' by 2 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

nothing to commit, working tree clean

One additional thing that can be related as I think this problem only started happening after I enabled it is ff=only in my Git config – the full section looks like this:

[pull]
    rebase = false
    ff = only

I also looked in the VS Code logs and there's an additional git fetch before – I'm not sure if this changes something or not:

[2022-05-04T06:27:11.853Z] > git fetch [2373ms]
[2022-05-04T06:27:11.853Z] From https://github.com/shoptet/sofa
 * [new branch]          1997-fix-pnpm -> origin/1997-fix-pnpm
 * [new branch]          debug-build   -> origin/debug-build
[2022-05-04T06:27:11.892Z] > git symbolic-ref --short HEAD [3ms]
[2022-05-04T06:27:11.897Z] > git for-each-ref --format=%(refname)%00%(upstream:short)%00%(objectname)%00%(upstream:track) refs/heads/master refs/remotes/master [4ms]
[2022-05-04T06:27:11.901Z] > git remote --verbose [3ms]
[2022-05-04T06:27:11.905Z] > git for-each-ref --sort -committerdate --format %(refname) %(objectname) %(*objectname) [7ms]
[2022-05-04T06:27:11.909Z] > git config --get commit.template [3ms]
[2022-05-04T06:27:12.498Z] > git pull origin master [1918ms]
[2022-05-04T06:27:12.498Z] From https://github.com/shoptet/sofa
 * branch                master     -> FETCH_HEAD
fatal: Cannot fast-forward to multiple branches.

I'd like to understand what the error means and how to get rid of it.

I'm on Git 2.36.0 and VS Code 1.66.2.

like image 562
Borek Bernard Avatar asked Sep 13 '25 01:09

Borek Bernard


1 Answers

From this related GitHub issue ticket: Git error (Cannot fast-forward to multiple branches.) when syncing during autofetch #158309, quoting jeffrson, the cause of the issue appears to be this:

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".

A fix is still pending. You can give that issue ticket a thumbs up to show support for it getting fixed, and subscribe to it to get notified about discussion and progress. But please avoid making noisy comments there like "+1" / "bump". I'll keep this answer post updated.

Though I haven't tried, someone in the comments here says they can work around it by doing git fetch --all and then git pull.

like image 89
starball Avatar answered Sep 15 '25 15:09

starball