I own a gitlab account with groups and subgroups. I have an access-token.
Using the access-token as the user-name/PW I can pull and push to one of my private repositories.
But I cannot get the token to work with my public repository. I can pull, but it denies access for push.
I’m using Windows. I have my account UN and PW set up on Windows Credential Manager.
Where am I going wrong?
git remote set-url origin https://<Token-name>:<pw>@gitlab.com/.git
git pull origin main // say’s its up to date.
git push origin main // says I don’t have access
Hey Stephen,
What is the exact error message you’re getting?
Perhaps you are not allowed to push to main (protected branch).
> git push origin main
remote: You are not allowed to push code to this project.
fatal: unable to access 'https://gitlab.com/qa-prog/Get-Started.git/': The requested URL returned error: 403
If I try:
> git remote set-url origin https://<user-name>:<pw>@gitlab.com/qa-prog/Get-Started.git
fatal: unable to access 'https://gitlab.com/qa-prog/Get-Started.git/': URL using bad/illegal format or missing URL
I had previously been able to push to this repo. Could the creation of an access-token have anything to do with my trouble?
I had a special character in my PW which needed URL-encoding. I’ve changed my PW and I can now push using this format:
git remote set-url origin https://<user-name>:<pw>@gitlab.com/qa-prog/Get-Started.git
Can you explain why it denies access but does not request my PW when I just use:
git remote set-url origin https://<user-name>@gitlab.com/qa-prog/Get-Started.git
TBH I’m not sure. It’s not necessarily a GitLab thing, so you might as well try to google around.
May I ask is there a reason why you don’t use SSH keys?
Generally, I’d suggest you to use SSH keys for authenticating. They are way more secure and easier to use when it comes to managing git authentication (e.g. cloning / pushing etc). Why? Imagine you change your username/password or your project token expires, you need to update every project’s origin URL. SSH keys don’t expire, and if it leaks, or you need to change it for whatever reason, you can disable it in GitLab and locally you need to exchange only 2 files in one place (instead of 5, 10, 20 projects)