I know how to provide a username and password to an HTTPS request like this:
git clone https://username:password@remote
But I\'d like to kn
I solved this problem in the following way:
This is an excellent Stack Overflow question, and the answers have been very instructive, such that I was able to resolve an annoying problem I ran into recently.
The organization that I work for uses Atlassian's BitBucket
product (not Github), essentially their version of GitHub so that repositories can be secured completely on premise. I was running into a similar problem as @coordinate, in that my password was required for a new repository I checked out. My credentials had been saved globally for all BitBucket
projects, so I'm not sure what prompted the loss of credentials.
In short, I was able to enter the following GIT command (supplying only my username), which then prompted Git's Credential Manager to prompt me for the password, which I was then able to save.
git clone https://user@code.domain.org/git/[organization]/[team]/[repository.git]
NOTE: the bracketed directory sub-paths simply refer to internal references, and will vary for you!
The user@host:path/to/repo
format tells Git to use ssh to log in to host
with username user
. From git help clone:
An alternative scp-like syntax may also be used with the ssh protocol:
[user@]host.xz:path/to/repo.git/
The part before the @
is the username, and the authentication method (password, public key, etc.) is determined by ssh, not Git. Git has no way to pass a password to ssh, because ssh might not even use a password depending on the configuration of the remote server.
ssh-agent
to avoid typing passwords all the timeIf you don't want to type your ssh password all the time, the typical solution is to generate a public/private key pair, put the public key in your ~/.ssh/authorized_keys file on the remote server, and load your private key into ssh-agent. Also see Configuring Git over SSH to login once, GitHub's help page on ssh key passphrases, gitolite's ssh documentation, and Heroku's ssh keys documentation.
If you have multiple accounts at a place like GitHub or Heroku, you'll have multiple ssh keys (at least one per account). To pick which account you want to log in as, you have to tell ssh which private key to use.
For example, suppose you had two GitHub accounts: foo
and bar
. Your ssh key for foo
is ~/.ssh/foo_github_id
and your ssh key for bar
is ~/.ssh/bar_github_id
. You want to access git@github.com:foo/foo.git
with your foo
account and git@github.com:bar/bar.git
with your bar
account. You would add the following to your ~/.ssh/config
:
Host gh-foo
Hostname github.com
User git
IdentityFile ~/.ssh/foo_github_id
Host gh-bar
Hostname github.com
User git
IdentityFile ~/.ssh/bar_github_id
You would then clone the two repositories as follows:
git clone gh-foo:foo/foo.git # logs in with account foo
git clone gh-bar:bar/bar.git # logs in with account bar
Some services provide HTTP access as an alternative to ssh:
GitHub:
https://username:password@github.com/username/repository.git
Gitorious:
https://username:password@gitorious.org/project/repository.git
Heroku: See this support article.
WARNING: Adding your password to the clone URL will cause Git to store your plaintext password in .git/config
. To securely store your password when using HTTP, use a credential helper. For example:
git config --global credential.helper cache
git config --global credential.https://github.com.username foo
git clone https://github.com/foo/repository.git
The above will cause Git to ask for your password once every 15 minutes (by default). See git help credentials for details.
Follow this arguments to replace with ur special cases if they are creating an issue:
! # $ & ' ( ) * + , / : ; = ? @ [ ]
%21 %23 %24 %26 %27 %28 %29 %2A %2B %2C %2F %3A %3B %3D %3F %40 %5B %5D
So for example-
actual URL: https://usern@me:p@ssword@git/reponame.git
Solution URL to use: https://usern%40me:p%40ssword@git/reponame.git