87

When I commit something in Mercurial like this:

hg commit -m "username question"

I see this output:

No username found, using 'WindowsVistaAdmin@ChunkyMonkey' instead

ChunkyMonkey is my Windows machine name and obviously WindowsVistaAdmin is the user that I am signed in as on this machine.

How can I set the username to something more respectable, or, at least, more concise?

tent
  • 1,069
  • 2
  • 9
  • 9

5 Answers5

128

In your ~/.hgrc (*nix) or mercurial.ini (Windows) file:

[ui]
username = First Last <email@address.com>

(mercurial.ini is in C:\Documents and Settings\[username]\ for XP and lower, C:\Users\[username]\ for Vista and higher. You can also run hgtk userconfig if you have TortoiseHg installed and do it that way.)

tghw
  • 25,208
  • 13
  • 70
  • 96
33

you can specify your username on the command line directly if you want to using --config. eg

hg --config ui.username=frymaster -m "comment here" commit

in fact, you can override anything in your .hgrc with this command. just look at your .hgrc and note the format:

[section]
key=val

that translates directly to

hg --config section.key=val
frymaster
  • 664
  • 7
  • 12
  • Perfect for inserting another developer's changes into the repo! – sage Jun 17 '15 at 19:31
  • For what possible reason is this not in mercurial's documentation/help? I thought I could do this, but almost resolved to thinking mercurial was just retarded and didn't allow it when I didn't find it via `hg config -h`, `hg config -h --verbose`, `hg help config`, nor online at https://www.selenic.com/mercurial/hg.1.html#config – naki Apr 02 '16 at 21:51
  • 2
    Oh... nevermind. You said `--config` rather than `config`: it's an option for other commands, used for command-level overriding... still not what I want. GRRR....Why can't I just type `hg config -l ui.username=username for this repo`. This would allow for the easy implementation of identity-setting aliases: `[alias] identity1=config -l ui.username=my prewritten user info all ready to be designated for use on of many newly cloned repos with various identities associated`. – naki Apr 02 '16 at 22:12
16

Information from here:

Setting up a username

When you try to run hg commit for the first time, it is not guaranteed to succeed. Mercurial records your name and address with each change that you commit, so that you and others will later be able to tell who made each change. Mercurial tries to automatically figure out a sensible username to commit the change with. It will attempt each of the following methods, in order:

  1. If you specify a -u option to the hg commit command on the command line, followed by a username, this is always given the highest precedence.
  2. If you have set the HGUSER environment variable, this is checked next.
  3. If you create a file in your home directory called .hgrc, with a username entry, that will be used next. To see what the contents of this file should look like, refer to the section called “Creating a Mercurial configuration file” below.
  4. If you have set the EMAIL environment variable, this will be used next.
  5. Mercurial will query your system to find out your local user name and host name, and construct a username from these components. Since this often results in a username that is not very useful, it will print a warning if it has to do this.

If all of these mechanisms fail, Mercurial will fail, printing an error message. In this case, it will not let you commit until you set up a username.

You should think of the HGUSER environment variable and the -u option to the hg commit command as ways to override Mercurial's default selection of username. For normal use, the simplest and most robust way to set a username for yourself is by creating a .hgrc file; see below for details.

Catskul
  • 17,916
  • 15
  • 84
  • 113
Andrew Flanagan
  • 4,267
  • 3
  • 25
  • 37
  • 7
    is there a possibility to set a username by repository ? – edomaur Sep 19 '09 at 11:06
  • 4
    @edomaur , yes it is, you must edit the `./hg/hgrc` file in the repository in question, where you need to set `username = Dev server` in the `[ui]` section – d.k Oct 28 '13 at 14:15
5

Here is how my windows /users/xxx/mercurial.ini looks. I don't have to enter username or passwords for anything. Looks like it might be repo specific. I have tortoiseHG installed, not sure if that makes any difference.

[ui]
username=mbroekhuis

[auth]
repo.prefix=http://myrepo
repo.username=mbroekhuis
repo.password=secret
Matt Broekhuis
  • 1,985
  • 2
  • 26
  • 35
3

For anyone trying to use HG workbench

settings

enter image description here

user global settings

enter image description here

Edit File

enter image description here

Save

kuhajeyan
  • 10,727
  • 10
  • 46
  • 71