Git OAuth 2.0 is the standard way to grant Git clients secure access to remote repositories without sharing passwords. Instead of static credentials, it uses short-lived tokens issued by an authorization server. When the token expires, your client refreshes it through a flow defined in the OAuth 2.0 spec. This eliminates the need to store plain-text passwords and reduces attack risk.
Most Git hosting providers — GitHub, GitLab, Bitbucket, Azure DevOps — support OAuth 2.0 for command-line and API access. The process is simple in theory:
- Register your application with the provider.
- Request authorization by sending the user to a URL with client ID, scopes, and redirect URI.
- Exchange the authorization code for an access token.
- Use the token in HTTPS Git operations.
OAuth 2.0 scopes control what the token can do. For Git, the typical scope is repo for full repository access or read:repo for read-only. Limiting scopes is best practice. Use refresh tokens if the provider supports them.