Can't set an alias with an external command in Git

Viewed 22
  1. git config --global alias.cdmy "!cd D:; cd D:\Download progy\OpenServer\domains"
  2. git cdmy

cd D:; cd D:\Download progy\OpenServer\domains: line 0: cd: too many arguments

I am learning Git With short commands, the alias is obtained. With the cd command, no. I would be grateful for your help

1 Answers

You may or may not be able to get Windows to accept your cd command,1 but having an alias run a shell that runs a cd command is not useful. The reason is that the shell itself exits as soon as the alias finishes running. The directory-changing operation affects only that shell and commands that that shell runs. Once the shell exits, you're back in the place you started from.

Think of the shell as a sort of agent (secret or otherwise). You send the agent to Greece, or some other foreign country, where he carries out some plot, and then commits suicide. You're somehow expecting to find yourself in Greece (or that other country) as a result. It's not going to happen: the agent went there; you stayed put.


1Because Windows Git uses bash to run commands (bash is the "secret agent" in the analogy above), you'd have to put quotes around the D:\Download progy\OpenServer\domains: Unix-style shells like bash break words at spaces so the shell believes you're asking it to travel to both D:\Download and, at the same time, progy\OpenServer\dmains. That's not one country/state/city with a name with a space in it, but rather two places.

Related