Step 1: Install GitHub CLI
Depending on your operating system, the instructions may vary:
For Windows: You can download the latest version of GitHub CLI from the GitHub CLI Releases page. Choose the .msi file for Windows and run it.
For MacOS: You can install the GitHub CLI using Homebrew by typing the following command in your terminal:
brew install gh
For Linux: Depending on your distribution, the command may vary:
For Fedora, use:
sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
sudo dnf install gh
Once the installation is complete, you can verify it by opening a new terminal window and typing:
gh --version
This should display the installed version of GitHub CLI.
Step 2: Create a Personal Access Token
In your web browser, navigate to GitHub and sign in to your account.
Click on your profile photo in the top-right corner and select “Settings” from the dropdown menu.
In the Settings sidebar, click on “Developer settings.”
In the Developer settings sidebar, click on “Personal access tokens.”
Click on “Generate new token.”
Give your token a descriptive name in the “Note” field.
In the “Select scopes” section, select the permissions you want to grant this token. To create a new project, you’ll need at least “repo” access.
Click “Generate token” at the bottom of the page.
After generating the token, be sure to copy it to a secure place. You won’t be able to see it again. This token can now be used in place of a password when performing Git operations over HTTPS, or when using the GitHub API.
Step 3: Authenticate GitHub CLI with the Personal Access Token
Back in your terminal, type:
gh auth login
Choose “Paste an authentication token” and enter your newly created personal access token when prompted.
You are now ready to use GitHub CLI with your new project.