Using Mercurial (hg) through a proxy

I had been searching and researching  on how to use mercurial through proxy. Even updating Ubuntu is not straightforward if you are lying behind the proxy. If you google it out, you will come across many forums that suggests proper command to be used. But I think there are some restrictions that I discovered today.

(PS: I might be wrong at many places, So please feel absolutely free to correct me. Your opinions/suggestions are most welcome)

Usually, in proxy environment, every user has its own account and it is possible to connect to network only after logging in.

Steps to Follow:

  1. Edit/create the following files as shown below:
sudo gedit /etc/apt/apt.conf

And add the foll. content

Acquire::http::proxy "http://username:password@proxy-host:port-number";

Acquire::ftp::proxy "http://username:password@proxy-host:port-number";

For example:

Acquire::http::proxy "http://1421900:amodnn@";


sudo gedit /etc/apt/apt.conf.d/apt.conf

Add the same “Acquire” statements to this file as well.

(PS: I dont know whether editing both the files is required. Expecting an answer from you :P)

2. Let us say, I want to clone mozilla-central,

the usual command:

hg clone

Now, in presence of proxy, the command complicates to something like this:

hg --config --config http_proxy.user="username” --config http_proxy.passwd=”password" clone 

For example,

hg --config --config http_proxy.user="14219000" --config http_proxy.passwd="amodnn" clone

Few instructions: (when you don’t follow so, you get some AMAZING errors which will force your cognitive senses to believe that it has to do something with Hardware…having no clue that those were just syntactical errors :P)

  • In password we cannot include any special characters, esp. ‘@’ and ‘!’ since the ‘Acquire’ command considers it as the end of password. Even enclosing it under the quotes/double quotes won’t work.

say, my password is: amod@123

so, the command will be

Acquire::http::proxy "http://1421900:amod@123@"

and same in the case of ‘clone’ command,

  • In “Acquire” cmd, dont forget to terminate the stmnt with semicolon, many ppl forget that.

Performing hg pull and update operations:


  1. If you are having a dedicated account in your institution then you need to add your user and group to the list of trusted entities.
sudo gedit /etc/mercurial/hgrc

And add the following lines

  1. Add those lines to .hgrc file as well, preferably update both the files (one at home folder and that in .hg folder

And then you may request pull operation as follows

hg --config --config http_proxy.user="username” --config http_proxy.passwd=”password" pull

These were some of my experiences. Please let me know (by comments) if you get to know a better way than mentioned. It would be helpful for me as well to improve.


One thought on “Using Mercurial (hg) through a proxy

  1. Editing only the /etc/apt/apt.conf should do the job. Try it out. I do not have access to an Ubuntu machine at the moment to try it out, but it should work… 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s