20

When inside a git repository in Powershell or CMD, issuing

git mv * whatever

will return

fatal: bad source, source=*, destination=whatever

This works fine when using MSYS (Git Bash).

Ezequiel
  • 302

5 Answers5

14

As has been pointed out by others in this thread, the star does not automatically expand to file names in PowerShell. Thus, the command let get-childItem needs to be used, which explicitely tells PowerShell to expand wildcard characters.

You want to put the result of get-childItem * into parentheses so that they are expanded before the entire git mv command is executed:

git mv (get-childItem *) whatever

To save a few key strokes, you might want to use the alias gci for get-childItem:

git mv (gci *) whatever
5

As @PetSerAI said, the Windows command prompt and PowerShell will not expand the globing characters and it makes git mv fail.

Use a bash shell like MSYS instead.

georgiosd
  • 159
3

Using PowerShell to move the content of source to whatever folder you can run this command:

Get-ChildItem .\source\ | ForEach-Object { git mv $_.FullName .\whatever\ }

Your directory structure would look like this before:

+--C:\code\Project\
|
+----+bootstrap.py
+----+requirements.txt
+----+.gitignore
+----+source
|
+---------+manage.py
+---------+modules
+---------+templates
+---------+static
+----+whatever
|
+---------+cool.py

And after running would look like this:

+--C:\code\Project\
|
+----+bootstrap.py
+----+requirements.txt
+----+.gitignore
+----+source
+----+whatever
|
+---------+cool.py
+---------+manage.py
+---------+modules
+---------+templates
+---------+static
Nick
  • 141
2

Solution for cmd

for %i in (*) do git mv %i whatever/
-1

This also happens when you "source" directory doesn't exist.

Adam Rabung
  • 149
  • 1
  • 4