Contents

Setup git client for https access to github using token

I needed to connect to company’s github.com domain access with organizations SSO. Some of local script refers to the github.com space with https access which requires configuration for token setup by github CLI.

Add remote URL (if applicable)

For accessing to new remote address, you may add remote url by git remote add command.

1
2
3
4
5
6
7
$ git remote add origin https://github.com/user/repo.git
# Set a new remote

$ git remote -v
# Verify new remote
> origin  https://github.com/user/repo.git (fetch)
> origin  https://github.com/user/repo.git (push)

Ref. Github Docs | Managing remote repositories

Generating a personal access token

Github > settings > Developer settings > personal access tokens

On GUI, Give your descriptive name, Expiration, select permission, and click “Generate Token”.

After creating token, you can use the token as a password that is required by prompt.

1
2
3
$ git clone https://github.com/username/repo.git
Username: your_username
Password: your_token

Ref. Github Docs | Creating a personal access token

Caching github credential in git

  1. Install github CLI

  2. Configure by gh auth login

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
% gh auth login                        
? What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations? HTTPS
? Authenticate Git with your GitHub credentials? Yes
? How would you like to authenticate GitHub CLI? Paste an authentication token
Tip: you can generate a Personal Access Token here https://github.com/settings/tokens
The minimum required scopes are 'repo', 'read:org', 'workflow'.
? Paste your authentication token: ****************************************
- gh config set -h github.com git_protocol https
✓ Configured git protocol
✓ Logged in as username

Ref. Github Docs | Caching your GitHub credentials in Git

Re-authorize github application

Sometime, github requires re-authorized application during process for accessing over https.

To re-authorize, you can go to your settings on GitHub -> Applications -> Authorized OAuth Apps, find “GitHub for VSCode”, and choose “Revoke” from the “…” menu. If you then sign out in VSCode and sign in again, you should be prompted to re-authorized

Ref. microsoft / vscodecan’t re-authorize for github #99535