Skip to main content

2024-09-05

Quote

"There is no sudden disillusionment. There is only the gradual realization accumulated over time." —— Mi Le - Quotations · Wukong


Switching Git from SSH to HTTPS Access Token

git remote set-url origin https://url

Configuring a Global Access Token

git config credential.helper store
git config --global url."https://oauth2:<access token>@<git url>".insteadof "https://<git url>"

Explanation of the Command

This command uses git config to set a global configuration that automatically replaces https://<git url> with https://oauth2:<access token>@<git url> when interacting with Git repositories.

Breakdown of the command:

  • git config --global: Applies the configuration globally (effective for all repositories under the current user).
  • url."https://oauth2:<access token>@<git url>".insteadof: Specifies a URL substitution rule. Git will replace https://<git url> with the provided URL containing the access token.
  • "https://<git url>": The original remote repository URL.
  • https://oauth2:<access token>@<git url>: The substituted URL, where <access token> should be replaced with your actual GitLab access token.

How it works:
When you perform Git operations (e.g., git push, git clone) targeting https://<git url>, Git automatically uses https://oauth2:<access token>@<git url> instead. This embeds the OAuth 2.0 access token in the request, authenticating you without requiring manual username/password input.