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 mainBranching
# 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 # RemoteUndo 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-hashView History
# Log
git log --oneline --graph
# Show changes
git diff
# Show specific commit
git show commit-hashVSCode 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
| Feature | How to Access |
|---|---|
| Stage file | Click + next to file |
| Stage all | Click + next to “Changes” |
| Discard changes | Right-click → Discard Changes |
| View diff | Click filename in sidebar |
| Commit | Type message → ✓ Commit |
| Push | … menu → Push |
| Pull | … menu → Pull |
| Branch | Bottom-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
| Shortcut | Action |
|---|---|
Ctrl/Cmd + Shift + G | Open Source Control |
Ctrl/Cmd + Enter | Commit (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 loginCommon 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/repoWorkflow 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 readyTroubleshooting
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 --forceSSH vs HTTPS
Switch to SSH (no password prompts):
git remote set-url origin git@github.com:username/repo.gitGenerate SSH key: ssh-keygen -t ed25519 -C "email@example.com"