Part 7

Integrating GitHub with VS Code

To work more effectively with GitHub, it’s essential to integrate it with an IDE like VS Code. There are two ways to do this:


Method 1: Local Setup

This method involves installing Git on your local machine and using the GitHub Pull Request and Issues extension in VS Code.

Steps to Set Up Git with VS Code:

  1. Install Git (Version Control System) (if not installed)

    • Download and install Git from Git Downloads.
    • After installation, verify the installation by running:
      git --version
  2. Configure Git

After installing Git, you need to configure Git by providing your full name and email address.You can start GitHub Desktop and configure using the graphical user interface as shown in the diagram below or use the command line.

Configure Git with command line

  1. Open Git Bash.
  2. Set your username and email, which will be associated with your commits. Use these commands, replacing "Your Name" and "your.email@example.com" with your actual information:
git config --global user.name "Your Name"
git config --global user.email your.email@example.com

Check your Git Configuration

git config --list
  1. Install VS Code (if not installed)

  2. Install GitHub Pull Request and Issues Extension

    • Open VS Code and go to the Extensions Marketplace (Ctrl + Shift + X / Cmd + Shift + X on macOS).
    • Search for GitHub Pull Requests and Issues and install it.
    • Alternatively, install it directly from VS Code Extensions.
  3. Authenticate GitHub in VS Code

    • Open VS Code and navigate to:
      View > Command Palette (Ctrl + Shift + P / Cmd + Shift + P on macOS)
    • Search for "GitHub: Sign in to GitHub" and follow the prompts.
  4. Clone a GitHub Repository into VS Code

Read More: For full instructions, refer to the official VS Code guide: Collaborate on GitHub


Method 2: Using GitHub Codespaces (Cloud-Based IDE)

GitHub Codespaces is a cloud-based development environment that allows you to code directly in your browser without installing anything locally.

Benefits of GitHub Codespaces:

  • No installation required
  • Access your code from any device
  • Standardized development environment

How to Use GitHub Codespaces:

  1. Go to your GitHub repository.
  2. Click the "Code" button and select the "Codespaces" tab.
  3. Click "New codespace" to launch a fully configured VS Code environment in your browser.

Watch this short video on how to use GitHub Codespaces:

For more details, visit the official documentation: GitHub Codespaces


Which Method Should You Use?

  • Use the local method if you prefer working locally and need full control over your development environment.
  • Use GitHub Codespaces if you want to code from anywhere without worrying about installations.

Basic Git Command Line Reference

Here are some essential Git commands to get started:

CommandDescription
git --versionCheck if Git is installed
git config --global user.name "Your Name"Set your Git username
git config --global user.email "your-email@example.com"Set your Git email (must match GitHub)
git config --listView your Git configuration
git initInitialize a new Git repository in a folder
git clone <repo-url>Clone a repository from GitHub
git statusCheck the status of your working directory
git add <file>Stage a file for commit
git add .Stage all modified files for commit
git commit -m "Your commit message"Commit changes with a message
git log --oneline --graph --allView commit history in a readable format
git branchList all branches in the repository
git checkout -b <branch-name>Create and switch to a new branch
git merge <branch-name>Merge a branch into the current branch
git push origin <branch-name>Push changes to GitHub
git pull origin <branch-name>Pull the latest changes from GitHub
git remote -vShow linked remote repositories
git reset --hard <commit-id>Reset to a specific commit (dangerous, use with caution)

For a complete list of Git commands, check the official Git documentation: Git Command Reference

You have reached the end of this section! Continue to the next section:

You can check your current points from the blue blob in the bottom-right corner of the page.