Share
Explore

GitHub Command Line Interface (CLI) Lab Guide - current

You can also refer to this Lab More for more details:

image.png

The GitHub CLI allows you to interact with GitHub directly from your terminal, streamlining your development workflow.

Installation and Setup

Initial Setup
Download GitHub CLI from cli.github.com
Install the package for your operating system
Authenticate by running:
image.png
bash
gh auth login


Generate a personal authentication token since this is the preferred login method
image.png
image.png

note

Here's a detailed lab instruction to generate a Personal Access Token (PAT) in GitHub:

Generating a Personal Access Token in GitHub

Step 1: Access GitHub Settings

Log in to your GitHub account.
Click on your profile picture in the top-right corner of the page.
Select "Settings" from the dropdown menu.

Step 2: Navigate to Developer Settings

In the left sidebar of the Settings page, scroll down and click on "Developer settings".
image.png

Step 3: Access Personal Access Tokens

In the left sidebar of the Developer settings page, click on "Personal access tokens".
Select "Tokens (classic)" if you want to create a classic token, or "Fine-grained tokens" for more granular control
.

Step 4: Generate New Token

Click on "Generate new token" for classic tokens, or "Generate new token" for fine-grained tokens
.
You may be prompted to enter your GitHub password for security reasons.
image.png

Step 5: Configure Token Settings

In the "Note" field, enter a descriptive name for your token.
Set an expiration date for your token by selecting an option from the "Expiration" dropdown menu
.
For classic tokens, select the scopes (permissions) you want to grant to this token. For fine-grained tokens, you can set more specific permissions
.

Step 6: Create and Save Token

Scroll to the bottom of the page and click "Generate token".
Your new personal access token will be displayed. IMPORTANT: Copy this token immediately and store it securely. You won't be able to see it again
.

Step 7: Use Your Token

You can now use this token for authentication in place of your password when performing Git operations over HTTPS
. For example:

git clone https://github.com/USERNAME/REPO.git
Username: YOUR-USERNAME
Password: YOUR-PERSONAL-ACCESS-TOKEN

Remember to keep your token secure and never share it publicly. If you believe your token has been compromised, you should revoke it immediately and generate a new one.
For the github lab: go to your command window and directory, and do this:

gh auth login

image.png
image.png

image.png
image.png
image.png

Now review these updated files on the GitHUB repository

image.png
Now let’s demonstrate making changes on the Cloud and pulling (syncing) them down to local
image.png
image.png

Basic Commands

Repository Operations
bash
# Clone a repository
gh repo clone username/repository

# Create a new repository
gh repo create

# Fork a repository
gh repo fork username/repository

Working with Pull Requests

Creating Pull Requests
bash
# Create a new pull request
gh pr create

# List pull requests
gh pr list

# Check out a pull request locally
gh pr checkout [PR-NUMBER]

Reviewing Pull Requests
bash
# View PR status
gh pr status

# Review a pull request
gh pr review [PR-NUMBER]

# Merge a pull request
gh pr merge [PR-NUMBER]

Common Workflows

Pulling from Repository
bash
# Fetch and pull latest changes
gh repo sync

# Pull specific branch
git pull origin [branch-name]

Pushing to Repository
bash
# Stage changes
git add .

# Commit changes
git commit -m "Your commit message"

# Push to remote
git push origin [branch-name]

Advanced Features

Issue Management
bash
# Create new issue
gh issue create

# List issues
gh issue list

# Close issue
gh issue close [ISSUE-NUMBER]

Repository Maintenance
bash
# View repository status
gh repo view

# List repository contributors
gh repo contributors

Best Practices

Always pull before starting new work
Create descriptive commit messages
Use branches for new features
Review changes before pushing
Keep your local repository up to date

Troubleshooting

Common Issues
cmd window:
# Reset authentication
gh auth logout
gh auth login

# Check CLI version
gh --version

# Get help
gh help




Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.