-3

I'm trying to run the following command in a command prompt, with single percentage for the argument, as it should be for command prompt instructions:

for /F %remote in ('git branch -a') do (git branch --track %remote) && git fetch --all && git pull --all

But I still get the following error:

%remote was unexpected at this time.

There's a lot of issues with this "argument was unexpected at this time". I've searched and searched but almost all solutions refer to the same confusion between using % or %%. Double percentages should only be used in batch files. But I'm using the proper notation. Why doesn't it work?

Could it be because of the parenthesis? I don't know if this issue mentioned on Microsoft's website is relevant or not.

Koby Douek
  • 16,156
  • 19
  • 74
  • 103
Axonn
  • 10,076
  • 6
  • 31
  • 43

1 Answers1

2

Read the Documentation

C:\>for /?
Runs a specified command for each file in a set of files.

FOR %variable IN (set) DO command [command-parameters]

  %variable  Specifies a single letter replaceable parameter.

Notice how the 3rd line of the documentation says "single letter"

(the complete help text is 153 lines long. I recommend reading it ALL)

abelenky
  • 63,815
  • 23
  • 109
  • 159
  • Your avatar probably represented you pretty clearly as you were typing that eh? :). Thank you. – Axonn Mar 14 '17 at 13:32
  • 3
    @Axonn, an astute observation! To bad the eye roll wasn't an animated. LOL. – Squashman Mar 14 '17 at 13:40
  • I'm confused, is the third line what is missing from the command? – cloudiebro Jun 13 '23 at 00:10
  • 1
    @cloudiebro: The OP tried to use loop variable `%remote`. The documentation clearly says loop variables must be ***a single letter***. `%r` is OK, but `%remote` is more than a single letter and not OK. Their command should be: `for %r in (...) do (...)` – abelenky Jun 13 '23 at 14:55