1

I cloned the origin remote repo to my local repository using my generated Personal access token. Now I want to push commit changes to my remote repository, git is asking for password.

I searched around here and I found help in setting my origin URL from SSH to HTTPS using;

git remote set-url origin https://<PERSONAL_ACCESS_TOKEN>@github.com/<Username>/<repo>.git

I confirmed the change using git remote -v its now showing

origin  https://ghp_kGuXXXXXXXXXXXXXXXXXXXXXXX8dd@github.com/<correct_user>/<right_repo>.git (fetch)                                
origin  https://ghp_kGuXXXXXXXXXXXXXXXXXXXXXXX8dd@github.com/<correct_user>/<right_repo>.git (push)

Still, when I try git push it still ask for password. Please I need help. I'm frustrated already. How can I push to my remote repo using on PAT without password prompt.

Thundrizzy
  • 11
  • 1
  • 4
  • 2
    This is a simple syntactic error: as [kadewu answered](https://stackoverflow.com/a/72297372/1256452), the syntax is a literal `https://` followed by the user name followed by a colon followed by the PAT followed by an at-sign `@` followed by the host name followed by a slash followed by the repository path on that host. But remember that a token *is* a kind of password: by putting it into cleartext here, you are broadcasting the password to anyone who can look at things on your machine. It's usually wiser to keep these secret, using a credential manager. – torek May 19 '22 at 03:00
  • Thanks, I appreciate. The 'username:' after the 'https://' is it to be typed verbettim or to be replaced with my own username? – Thundrizzy May 19 '22 at 06:31
  • Replaced with your user name, yes. – torek May 19 '22 at 07:37
  • I just tried the answer provided by @kadewu and I'm getting an error message `fatal: authentication for failed`. What could still be wrong please? – Thundrizzy May 19 '22 at 20:17
  • Hard to be sure with https, but see [How can I debug git/git-shell related problems?](https://stackoverflow.com/q/6178401/1256452) – torek May 19 '22 at 20:55

1 Answers1

4

If you want to use PAT via URL in HTTPS you should define it this way.

git remote set-url origin https://username:token@github.com/put_username_here/repo-name.git

You are missing the username.

Roman Mahotskyi
  • 4,576
  • 5
  • 35
  • 68
kadewu
  • 336
  • 4
  • 8