V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
movq
V2EX  ›  程序员

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

  •  
  •   movq · 24 天前 · 1858 次点击

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

    7 条回复    2025-08-16 11:21:53 +08:00
    tangc1986
        1
    tangc1986  
       24 天前
    直接敲 bash 应该就可以吧
    nice66
        2
    nice66  
       24 天前
    把 git 的安装目录下的 bin 目录添加到环境变量,然后直接在 cmd 中直接输入 bash 回车
    hwdq0012
        3
    hwdq0012  
       24 天前
    那是因为 cmd 在环境变量 PATH 目录里,所以你可以直接执行, 你还可以在 git bash 里 ipcofnig 呢。。
    elechi
        4
    elechi  
       24 天前
    bash.exe -l -i
    Need4more
        5
    Need4more  
       24 天前
    我装了 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
        6
    UnluckyNinja  
       24 天前
    安装 git 时不是有选项添加到环境变量,勾上就行了(忘记勾了那就手动加一下,一样的)
    darklinden
        7
    darklinden  
       23 天前
    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"

    ```
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1134 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 18:07 · PVG 02:07 · LAX 11:07 · JFK 14:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.