windows terminal 中如何从 cmd 直接切换到 git bash

26 天前
 movq

在 git bash 中输出 cmd 然后按回车就能直接切换到 git bash, 但是在 cmd 中怎么切换到 git bash 呢

1891 次点击
所在节点    程序员
7 条回复
tangc1986
26 天前
直接敲 bash 应该就可以吧
nice66
26 天前
把 git 的安装目录下的 bin 目录添加到环境变量,然后直接在 cmd 中直接输入 bash 回车
hwdq0012
26 天前
那是因为 cmd 在环境变量 PATH 目录里,所以你可以直接执行, 你还可以在 git bash 里 ipcofnig 呢。。
elechi
26 天前
bash.exe -l -i
Need4more
26 天前
我装了 wsl ,也装了 git

做了个实验,直接敲 bash(.exe),会进入 wsl 环境

这是 cmd 的 where 命令输出:
C:\Users\xx>where bash
C:\Windows\System32\bash.exe
C:\Users\xx\scoop\shims\bash.exe
C:\Users\xx\AppData\Local\Microsoft\WindowsApps\bash.exe

我推测这里 bash.exe 应该是 wsl.exe 的别名

敲 git-bash 命令,弹出了 git bash 的窗口
UnluckyNinja
26 天前
安装 git 时不是有选项添加到环境变量,勾上就行了(忘记勾了那就手动加一下,一样的)
darklinden
25 天前
https://gist.github.com/darklinden/283d18c9112722d11cfd4c6fb7620f4e

```bat

@REM follow https://stackoverflow.com/questions/12870928/mac-bash-git-ps1-command-not-found
@REM download https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh
@REM to C:\Program Files\Git\etc\git-prompt.sh
@REM add `. /etc/git-prompt.sh` to your .bashrc or .bash_profile
@REM download https://github.com/git/git/blob/master/contrib/completion/git-completion.bash
@REM to C:\Program Files\Git\etc\git-completion.bash
@REM add `. /etc/git-completion.bash` to your .bashrc or .bash_profile

@echo off
setlocal enableextensions
set TERM=
"C:\Program Files\Git\bin\bash.exe" --login -i -c "export CURRENTDIR='%CD%'; cd \"$CURRENTDIR\"; exec /bin/bash"

```

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://ex.noerr.eu.org/t/1152595

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX