There are several ways to login to GitHub on the command line including passkeys, and store your Github credentials through credential managers. However, one of the easiest ways to go about this according to me is through a one-time browser-based login solution provided by the Github CLI! Through this, there is no need to go through Github to generate a passkey. Here is a step-by-step guide on how to go about doing this.
You may have already installed the git CLI, but for this task, you also need to install the Github CLI. On Linux, you can install this using
sudo apt install gh
On a Mac, you can utilize Homebrew or your favorite package manager to install the same as such
brew install gh
Once it is done installing, you are ready to run the command for the one-time login:
gh auth login
Click through the appropriate options, and then select the browser based login. Follow the on screen command on your browser, and enter the code in your browser that is present in your terminal. After this, you are logged in to get up on the command line.
Future Git commands should now not prompt you to enter your username or generate a passkey.
Hope this helped and saved you some time!