文章目录
- 1. PowerShell 里的 git 默认使用体验不够好
- 2. posh-git 介绍
- 2.1 安装 posh-git
- 2.2 PS1 显示的内容
- 2.3 补全分支
1. PowerShell 里的 git 默认使用体验不够好
在 Windows 系统上,安装了 git for windows 后, git bash 里的体验确实不错。 但是在 Windows11 系统里使用 PowerShell 的时候是非常多的,例如 VSCode 里按下 `Ctr+`` 快捷键后, 弹出的终端默认是 PowerShell。
PowerShell 中的 git, 缺少一些很好用的特性:
- 命令补全:例如输入
git checkout的时候, 输入git che后按下tab键,希望补全为git checkout. - 分支补全:例如当前在
dev分支, 想要切换回到main分支, 当输入git switch ma后, 按下了tab键,希望补全为git checkout main - 显示当前的分支名字,类似于
oh-my-zsh那样,在$PS1变量里标注
2. posh-git 介绍
posh-git 官方是 https://github.com/dahlbyk/posh-git
在 Pro Git 在线电子书中提到了 posh-git https://git-scm.com/book/zh/v2/附录-A%3A-在其它环境中使用-Git-Git-在-PowerShell-中使用-Git

2.1 安装 posh-git
管理员权限开启 PowerShell 后, 安装 posh-git 模块:
PowerShellGet\Install-Module posh-git -Scope CurrentUser -Force
任意一个 PowerShell 窗口, 加载 posh-git 模块:
Import-Module posh-git
也可以让 powershell 每次开启时自动加载 posh-git 模块,方法是
Add-PoshGitToProfile
不过这个配置会让 PowerShell 每次加载消耗1秒多, 建议不设置,需要的时候,临时输入 Import-Module posh-git。
2.2 PS1 显示的内容
例如 ncnn 本地仓库,落后于remote多个commit:

2.3 补全分支
例如打算切换到 azure-pipelines 分支,当输入完 azure 后按下 Tab 会自动补全为 azure-pipelines






![[0729] X-CMD 发布 v0.4.3:借助 fzf ,提升用户使用体验](https://i-blog.csdnimg.cn/direct/d3c3bc748a5b4fa8878de603f26e5cc7.png#pic_center)













