GIT: Calling git Clone Using Password with Special Character

gitlogoIt is more popular to use an ssh key instead of a password when automating a git clone from a guest OS.  But if you do need to specify the password directly into the console command, it takes this form:

$ git clone https://<user>:<password>@<gitserver>/<path>/<repo>.git

Which works fine if the password is plaintext, but if it has special characters like an exclamation mark, you need to use percent encoding which is often called URL encoding.

!   #   $    &   '   (   )   *   +   ,   /   :   ;   =   ?   @   [   ]
%21 %23 %24 %26 %27 %28 %29 %2A %2B %2C %2F %3A %3B %3D %3F %40 %5B %5D

For example, using the credentials myuser/password! to a github repository might look like:

$ git clone https://myuser:password%21@github.com/myuser/repo.git

Cached Credentials

If you are actively working on this repository and do not want to supply this password every time you perform a push, you can specify the use of a cache and the number of seconds it is valid:

$ git config --global credential.helper 'cache --timeout=3600'

 

REFERENCES

http://stackoverflow.com/questions/4565700/specify-private-ssh-key-to-use-when-executing-shell-command-with-or-without-ruby

http://superuser.com/questions/232373/how-to-tell-git-which-private-key-to-use

https://confluence.atlassian.com/bitbucket/set-up-ssh-for-git-728138079.html