27

When using Git for Windows "git bash" on Windows, how to conveniently print the working directory in Windows path representation, e.g.

D:\foo\bar

similar to using 'pwd' to get the Unix representation

/d/foo/bar/

such that the path can be read by Windows explorer and cmd console?

yhd.leung
  • 1,162
  • 1
  • 18
  • 27
  • 7
    Well, you can use `pwd -W`, but it uses forward slash, this is probably the closest you'll get. You can always do `cmd.exe /c cd`. – Lasse V. Karlsen Jun 30 '17 at 08:46
  • 1
    Thanks @Lasse, `pwd -W` is fit for my use-cases on Windows explorer and cmd console. I didn't realize they accept forward slash too. I really want to take your comment as answer. – yhd.leung Jun 30 '17 at 09:27

1 Answers1

48

In Git Bash:

$ cmd //c cd
C:\Program Files\Git

Note the double slash. And for forward slashes, as mentioned in the comments:

$ pwd -W
C:/Program Files/Git
vestlen
  • 1,103
  • 11
  • 17
  • Thanks @vestlen, single slash `cmd /c cd` also works. Why double slash ? – yhd.leung Feb 14 '18 at 02:16
  • 5
    @yhd.leung On my box at least, using the single slash leaves you sitting in the cmd shell. Using the double slash prints the directory and then exits cmd, returning you to the bash shell. – vestlen Jun 12 '18 at 20:55
  • 3
    To turn the slashes to back-slashed with `pwd -W`, just use: `pwd -W | sed 's,/,\\,g'` – Tilman Vogel Jan 21 '22 at 12:14