Guide to using GitHub from the terminal and VSCode.

Terminal Usage

Basic Commands

# Clone a repository
git clone https://github.com/username/repo.git
 
# Check status
git status
 
# Stage changes
git add filename.txt          # Stage specific file
git add .                     # Stage all changes
 
# Commit changes
git commit -m "Commit message"
 
# Push to remote
git push origin main
 
# Pull latest changes
git pull origin main

Branching

# Create new branch
git checkout -b feature-branch
 
# Switch branches
git checkout main
 
# Merge branch
git checkout main
git merge feature-branch
 
# Delete branch
git branch -d feature-branch  # Local
git push origin --delete feature-branch  # Remote

Undo Changes

# Unstage files
git reset HEAD filename.txt
 
# Discard local changes
git checkout -- filename.txt
 
# Amend last commit
git commit --amend -m "New message"
 
# Revert commit
git revert commit-hash

View History

# Log
git log --oneline --graph
 
# Show changes
git diff
 
# Show specific commit
git show commit-hash

VSCode with Git Extension

Built-in Git Support

VSCode has built-in Git integration. No extension needed for basic features.

Source Control Panel

Open: Ctrl+Shift+G (Windows/Linux) or Cmd+Shift+G (Mac)

Actions:

  • Changes → See modified files
  • + (hover) → Stage file
  • Message box → Type commit message
  • ✓ Commit → Commit staged changes
  • … menu → Push, pull, branch operations

Key Features

FeatureHow to Access
Stage fileClick + next to file
Stage allClick + next to “Changes”
Discard changesRight-click → Discard Changes
View diffClick filename in sidebar
CommitType message → ✓ Commit
Push… menu → Push
Pull… menu → Pull
BranchBottom-left corner → branch name

Extensions to Install

GitLens (recommended)

  • Adds blame annotations
  • Code lens for authors
  • Repository view
  • Heatmap

GitHub Pull Requests

  • Review PRs in editor
  • Create PRs
  • View comments

VSCode Shortcuts

ShortcutAction
Ctrl/Cmd + Shift + GOpen Source Control
Ctrl/Cmd + EnterCommit (with message)
Ctrl/Cmd + Shift + P → “Git: “Git commands

GitHub CLI (gh)

Install: brew install gh (Mac) or see cli.github.com

Authenticate

gh auth login

Common Commands

# Create repo
gh repo create repo-name
 
# View PRs
gh pr list
 
# Create PR
gh pr create --title "Title" --body "Description"
 
# Checkout PR
gh pr checkout 123
 
# View issues
gh issue list
 
# Clone
ggh repo clone username/repo

Workflow Tips

1. Commit Often

Small, focused commits are easier to review and revert.

2. Write Good Messages

feat: add user authentication
fix: resolve login redirect bug
docs: update README with setup instructions

3. Pull Before Push

Always pull latest changes before pushing.

4. Use Branches

Don’t commit directly to main. Use feature branches.

5. Review Before Commit

git diff --cached  # Review staged changes
git status         # See what's ready

Troubleshooting

Merge Conflicts

Terminal:

git status              # See conflicting files
# Edit files to resolve
git add .
git commit -m "Resolve merge conflict"

VSCode:

  • Conflicts show inline with “Accept Current” / “Accept Incoming” buttons
  • Use “Resolve in Merge Editor” for complex conflicts

Undo Last Push

# Careful! Rewrites history
git reset --soft HEAD~1
git push origin +main --force

SSH vs HTTPS

Switch to SSH (no password prompts):

git remote set-url origin git@github.com:username/repo.git

Generate SSH key: ssh-keygen -t ed25519 -C "email@example.com"

Resources