如何在 Windows 上更改 git bash 用户名?
假设我在 Windows 7 中的用户名是 Caesar。当我打开 Git Bash 时,我会看到类似的内容
凯撒@COMPUTER-NAME$
是否可以将我的用户名更改为小写(以便它与我拥有的各种 Linux 服务器一致):
凯撒@COMPUTER-NAME$
PS 在 cygwin 中,可以通过一种明显的方式编辑 /etc/passwd
来实现这一目标,但 git bash 没有这样的文件(可能有用)。
Assume that my username in Windows 7 is Caesar. When I open Git Bash I am greeted with something like
Caesar@COMPUTER-NAME$
Is it possible to change my username to be lowercase (so that it agrees with various Linux servers I have):
caesar@COMPUTER-NAME$
P.S. In cygwin, one can edit /etc/passwd
in an obvious way to achieve this, but there is no such file for git bash (might be useful).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您可以使用 ssh_config 工具指定不同的用户名。有关详细信息,请参阅 ssh_config 联机帮助页,但简要说明:
创建文件
~/.ssh/config
,然后在其中放入以下行:如果不同主机有不同的用户名,则可以使用主机设置指定不同的用户名,包括默认用户名:
通常,
~/.ssh/config
文件必须具有模式 600,但这对于 Git windows 版本似乎不是必需的。You can use the ssh_config facility to specify a different username. See an ssh_config manpage for details, but briefly:
Create the file
~/.ssh/config
, and put just this line in it:If you have different usernames for different hosts, you can use the Host setting to specify different usernames, including the default one:
Normally, the
~/.ssh/config
file has to have mode 600, but that doesn't seem to be necessary for the Git windows version.要同时使用 Git bash 用户名更改 windows 用户名(不能为大写):
To change windows username also with Git bash username (not for upper case):
该线程已有几年历史,但正确的答案是更改保存该信息的变量的值。
如果你稍微修改 git-prompt.sh 脚本(对我来说,它位于 c:\Program Files(x86)\Git\etc\profile.d\git-prompt.sh) ,您可以将标题设为任何您想要的内容。
注意:您需要以管理员身份运行 VS Code、Notepad++ 或类似工具才能写回此目录。
示例:
控制台:
This thread is a few years old, but the correct answer is to change the value of the variable that holds that information.
If you modify the git-prompt.sh script a bit (for me, this is located in c:\Program Files(x86)\Git\etc\profile.d\git-prompt.sh), you can make the title anything you want.
Note: You will need to run VS Code, Notepad ++ or similar as administrator to write back to this directory.
example:
console:
它基于
$PS1
的设置,即用于显示提示的内容。 username@computername 部分将由类似\u@\h$
的值生成。我不知道使\u
值小写的简单方法,但在您的个人资料中,您可以对用户名进行一些处理,并使用您想要的必要的小写值(或任何内容)并设置它到$PS1
It is based on what is set to the
$PS1
, which is what is used to display your prompt. The username@computername part would have been generated by a value like\u@\h$
. I am not aware of easy ways to make\u
value lowercase, but in your profile, you can do some processing with the username and use the necessary lowercase value ( or anything) that you want and set it to the$PS1
这并不完全是您想要的,但您也可以克隆/编辑您的遥控器以包含包含用户名的 URL。例如: git clone ssh://[电子邮件受保护]
It is not exactly what you want, but you can also clone/edit your remotes to have the URL with the username included. Ex.: git clone ssh://[email protected]
在 Windows 上,您可以通过在
C:\Users\{userName}\.config\git\
创建一个文件来实现此目的,并在此文件夹中创建一个名为git-prompt 的文件.sh
。在此文件中,您可以编写以下代码
该文件基本上由 git 使用。如果此文件存在,git 将查找此文件,否则它将使用存在于以下位置的默认配置
C:\Program Files(x86)\Git\etc\profile.d\git-prompt.sh
- 适用于 x86/32 位系统和
c:\Program Files\Git\etc\profile.d\git-prompt.sh
适用于标准 x64 位系统。上面的代码片段也从同一个文件中使用。
On windows, you can achieve this by creating a file at
C:\Users\{userName}\.config\git\
and inside this folder you can create a file with namegit-prompt.sh
.Inside this file you can write following code
This file is basically used by git. If this file exits, git will look for this file else it will use default config present at
C:\Program Files(x86)\Git\etc\profile.d\git-prompt.sh
- for x86/32 bit systemand
c:\Program Files\Git\etc\profile.d\git-prompt.sh
for a standard x64 bit system.This above code snippet is also used from same file.
步骤 1 只需转到您计算机的此位置 => C:\Program Files\Git\etc\profile.d
步骤2 在那里你会发现一个文件“git-prompt.sh”,用记事本以外的任何工具打开它。
Step-3 然后按照这个步骤=> https://ibb.co/xGxQ5Cf
工作已完成。
或者,您可以关注此 YouTube 视频 => https://youtu.be/VIWKc5sx5Ao?si=10UiAbDKqM-O5wQd
Step-1 Just go to this location of your computer => C:\Program Files\Git\etc\profile.d
Step-2 There you will find a file "git-prompt.sh", open it with anything other than notepad.
Step-3 Then follow this step => https://ibb.co/xGxQ5Cf
The work is finished.
Or, you can follow along this youtube video => https://youtu.be/VIWKc5sx5Ao?si=10UiAbDKqM-O5wQd