Linux – git pull with access token, git push with username / password

command-line-interface, git, linux

I've got a problem with git push. Here are many threads regarding this issue, but none of them fit to my problem.

The company I work for, has it's own gitlab. Policy is only https, no ssh is allowed. For cloning and pulling, an access token is required. Pushing only with username/password. Don't ask me about the underlaying reason. Unfortunately I don't know it.

Error message is:

$ git pushfatal: unable to access 'https://<username>:<AccessToken>@<domain>/<owner>/<reponame>.git/': The requested URL returned error: 403

At least I alread was able to clone a repo, but I'm failing to push the changed content respectively. Ubuntu 18.04 is running on my laptop.
What do I need to do to solve my issue?

Best Solution

You already know that every remote stores a URL: origin literally means https://<username>:<AccessToken>@<domain>/<owner>/<reponame>.git/.

What you didn't know is that every remote actually stores two URLs. One is used for git fetch, and the second one is used for push. The second URL defaults to being the same as the first URL, but if you set it, you can set it to anything else, such as the URL without the access token. To set the second URL, you can use git remote set-url --push:

git remote set-url --push origin <url>

If you're like me, you might want to know about git config --edit as well, which will open the configuration file (typically just .git/config) in the same editor you're having Git use for everything else, where you can just edit it directly. But git remote is the tool designed for fiddling with the settings attached to each remote-name.