Github login using access token via command line

Motivation

Solution

Run the following sequence of steps to figure out the solution

  • First Go to Github Tokens for your account
  • Then hit on Generate new token

    • Give appropriate Note for identifying it at a later date
    • Select proper Expiration time => You will need to regenerate your token after expiration
    • Select OAuth scopes as per requirement
    • Hit Generate Token at the end image

Note down the generated token as it won't be shown again, in a secure place

Now get back to command line (in my case PowerShell)

  • Make sure to check the email/username configured with git commandline global settings

    git config --global user.name
    git config --global user.email
    
  • Set the values accordingly, if they are not as intended

    git config --global user.name "your_github_username"
    git config --global user.email "your_github_email"
    
  • One can check all the config values by running the following

    git config -l
    git config -l --global  # shows only global config values
    
  • Set credential helper timeout to probably few hours or a day, so as to avoid the prompt for login on every git push/git pull command

    git config --global credential.helper "cache --timeout=86400"
    
  • Run git pull while at the root of the existing cloned repository

    Username for 'https://github.com' : username
    Password for 'https://github.com' : paste your personal token from earlier step here
    

You should all be setup until the timeout happens and the prompt appears again

Latest Blogposts

How to find a linux machine is a VM (Virtual Machine) or a Bare Metal

If you can SSH into a linux machine and want to find out if its baremetal or Virtual Machine

7 November 2023

Storing Github access token in git credential store

Using git credentials store the github access token to avoid the re-prompting of username and pwd

4 April 2023

Token generation for Registering Self Hosted Github Runner via REST API

Explains how to generate a token using github API to be used in turn with Github self hosted runner registration

21 March 2023

Setting up a Self Hosted Github Runner

Explains how to setup a Github self hosted runner and register

20 March 2023

Managing the NodeJS versions on Windows

Node Version Manager (nvm) helps in managing multiple NodeJS versions

13 November 2022

Customizing the Powershell terminal with oh-my-posh

Instructions on customizing the terminal in powershell with oh-my-posh and winget

7 July 2022