[How To] Save Mercurial Username And Password For Syncing (Push & Pull)

First of all, you should really use keyring like gnome-keyring to store password. Storing plain password in a text file is never a good idea.

Keyring extension is available for mercurial.

However, if you don't want to hassle with the mumbo jumbo and really don't mind the plain password, you can use the following method to prevent mercurial asking for username/password while syncing to server. (while push and pull)

In your .hgrc file add entry like below:

server1.prefix = bitbucket.org/user/repo/
server1.username = username
server1.password = password
server1.schemes = http https

server1.prefix = *
server1.username = username
server1.password = password
server1.schemes = http https
Now the explanation part:
[auth] defines the section for authentication.

You have to group prefix, username, password and schemes with one string. It can be any string but whatever follows that string is part of that group.

prefix is the url, you can use wild card here.

username as you can guess is the username and pasword is password for that url defined in prefix.

schemes defines if its used over http and/or https.

If this still is mumbo jumbo for you, you can add username and password in the URL itself. For eg: http://username:password@hg.domain.com
You can make this persistent by adding user name and password in default path of the repository in .hg/hgrc file.


  1. how the heck we can enable this keyring thing. No help so far from Keyring Hg site or pypi site


Post a Comment

Comments are moderated. No spam please.

Popular posts from this blog

Adobe Stand Alone Flash Player for Linux

Squid Access.log Meaning Explained

[Solved] invalid partition table on /dev/sda -- wrong signature 0.