In Git for windows "git bash", how to "print working directory" in Windows path format that is usable by cmd and Windows explorer?

28,179

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
Share:
28,179

Related videos on Youtube

yhd.leung
Author by

yhd.leung

Updated on February 14, 2020

Comments

  • yhd.leung
    yhd.leung about 4 years

    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?

    • Lasse V. Karlsen
      Lasse V. Karlsen almost 7 years
      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.
    • yhd.leung
      yhd.leung almost 7 years
      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
    yhd.leung about 6 years
    Thanks @vestlen, single slash cmd /c cd also works. Why double slash ?
  • vestlen
    vestlen almost 6 years
    @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.
  • Kanhaiya
    Kanhaiya over 2 years
    To turn the slashes to back-slashed with pwd -W, just use: pwd -W | sed 's,/,\\,g'