How to change the git bash username on Windows?
Asked Answered
L

7

15

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).

Lifework answered 19/10, 2011 at 3:7 Comment(0)
S
20

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:

User caesar

If you have different usernames for different hosts, you can use the Host setting to specify different usernames, including the default one:

Host rome1
  User caesar
Host rome2
  User brutus
Host *
  User romeo

Normally, the ~/.ssh/config file has to have mode 600, but that doesn't seem to be necessary for the Git windows version.

Salvage answered 15/11, 2011 at 19:10 Comment(2)
Thank you for the answer, but this doesn't work. What can be reason?Liegnitz
@dondublon: if Linux, did you do chmod 600 ~/.ssh/config? It will be ignored otherwise. If not that, can you provide an example, or perhaps ask your own SO question?Salvage
S
13

To change windows username also with Git bash username (not for upper case):

  • Open Command prompt
  • Enter netplwiz
  • Select the windows user account and click the Properties button
  • Enter the new name for the account
  • Save and restart your computer
Softy answered 26/11, 2018 at 6:40 Comment(1)
To run "netplwiz" on a git bash terminal, I had to open it with administrator privileges.Repatriate
L
3

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.

PS1='\[\033]0;$TITLEPREFIX:$PWD\007\]' # set window title
PS1="$PS1"'\n'                 # new line
PS1="$PS1"'\[\033[32m\]'       # change to green
PS1="$PS1"'\u@\h '             # user@host<space>
PS1="$PS1"'\[\033[35m\]'       # change to purple
PS1="$PS1"'$MSYSTEM '          # show MSYSTEM
PS1="$PS1"'\[\033[33m\]'       # change to brownish yellow
PS1="$PS1"'\w'                 # current working directory

example:

...
PS1="$PS1"'STACKOVERFLOW@ABC '    # user@host<space>
...
PS1="$PS1"'LOL '                  # show MSYSTEM
...

console:

STACKOVERFLOW@ABC LOL /
$
Leckie answered 8/5, 2020 at 0:57 Comment(1)
Since it's bash, you can use e.g. PS1+='\n\[\e[32m\]\u@\h ' # newline, green, user@host<spaceCreamcups
Z
1

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

Zealot answered 19/10, 2011 at 4:57 Comment(1)
This only changes the display. He wants the username itself changed so that it interacts nicely with other servers.Office
O
0

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]

Off answered 19/10, 2011 at 19:57 Comment(1)
I am aware. This is what I was actually trying to avoid :)Lifework
M
0

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 name git-prompt.sh.

Inside this file you can write following code

USER="Dev"                     # You can use any name you want to see in terminal

PS1='\[\033]0;$TITLEPREFIX:$PWD\007\]' # set window title
PS1="$PS1"'\n'                 # new line
PS1="$PS1"'\[\033[32m\]'       # change to green
PS1="$PS1"'$USER@\h '          # user@host<space>
PS1="$PS1"'\[\033[35m\]'       # change to purple
PS1="$PS1"'$MSYSTEM '          # show MSYSTEM
PS1="$PS1"'\[\033[33m\]'       # change to brownish yellow
PS1="$PS1"'\w'                 # current working directory
if test -z "$WINELOADERNOEXEC"
then
    GIT_EXEC_PATH="$(git --exec-path 2>/dev/null)"
    COMPLETION_PATH="${GIT_EXEC_PATH%/libexec/git-core}"
    COMPLETION_PATH="${COMPLETION_PATH%/lib/git-core}"
    COMPLETION_PATH="$COMPLETION_PATH/share/git/completion"
    if test -f "$COMPLETION_PATH/git-prompt.sh"
    then
        . "$COMPLETION_PATH/git-completion.bash"
        . "$COMPLETION_PATH/git-prompt.sh"
        PS1="$PS1"'\[\033[36m\]'  # change color to cyan
        PS1="$PS1"'`__git_ps1`'   # bash function
    fi
fi
PS1="$PS1"'\[\033[0m\]'        # change color
PS1="$PS1"'\n'                 # new line
PS1="$PS1"'$ '                 # prompt: always $

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 system and 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.

Meistersinger answered 5/1 at 10:31 Comment(0)
C
0

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

Candra answered 29/6 at 3:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.