I'm trying to clone a git repository with an access token following this guide:
git clone https://x-token-auth:{access_token}@bitbucket.org/user/repo.git
But this gives me the next error:
fatal: unable to access 'https://x-token-auth {access_token}@bitbucket.our_own_server.com/scm/rat/repo.git/':
Port number ended with '{'
I've tried many variants, with/out brackets, with/out quotes, admin or username instead of x-token-auth, but without any success.
Is this a configuration problem? Are there any alternatives?
PS: The access token contains '/' and '+'. Can this be the problem?
It looks like you're literally writing the text {access_token}
in the URL, but that isn't what was intended, nor is it valid URL syntax. You need to write the access token in that position using URI encoding.
The easiest way to do that is to encode every character in the token that isn't a letter or a digit as a hex escape of the form %HH
, where HH
is a two character hex value representing its ASCII value. So if your token contains a +
, you should instead replace it with %2B
, and you should replace every /
with %2F
. Similarly, if you have an =
, it should be %3D
, and so forth.
Alternatively, you could use a Git credential helper, and when prompted for the username, enter x-token-auth
, and when prompted for the password, enter the access token itself exactly as it is (without URI-encoding it as I mentioned above). Then Git will handle this for you.