Connect GitHub to VS Code
1. Install Git and VS Code
Section titled “1. Install Git and VS Code”- Download Git: git-scm.com
- Download Visual Studio Code: code.visualstudio.com
Check that Git is installed:
git --version2. Configure Git
Section titled “2. Configure Git”Set your identity (same information as on GitHub):
git config --global user.name "Your Name"git config --global user.email "your@email.com"Set VS Code as the default editor:
git config --global core.editor "code"3. Generate an SSH key
Section titled “3. Generate an SSH key”Create a new SSH key pair:
ssh-keygen -t rsa -b 4096 -C "your-email@example.com"You get two files in ~/.ssh/:
id_rsa→ private key (keep it secret)id_rsa.pub→ public key (share with GitHub)
4. Add the key to GitHub
Section titled “4. Add the key to GitHub”- Copy the public key:
cat ~/.ssh/id_rsa.pub- Go to GitHub → Settings > SSH and GPG keys > New SSH Key
- Paste the key, give it a name, save.
5. Enable the key locally
Section titled “5. Enable the key locally”Start the SSH agent and add the key:
eval "$(ssh-agent -s)"ssh-add ~/.ssh/id_rsa6. Connect VS Code to GitHub
Section titled “6. Connect VS Code to GitHub”- Open VS Code
- Install the GitHub Pull Requests and Issues extension
- Click bottom left on Sign in to GitHub
- Authorize access to your GitHub account
7. Clone a GitHub repository
Section titled “7. Clone a GitHub repository”In VS Code:
Ctrl + Shift + P→ type Git: Clone- Paste the SSH URL of the repository:
git@github.com:user/my-project.git- Choose a folder → VS Code opens the project automatically.
8. Typical workflow in VS Code
Section titled “8. Typical workflow in VS Code”- Source Control tab (branch icon in the sidebar)
- Main steps:
- Stage (
+) =git add - Commit (message required) =
git commit -m "Message" - Sync Changes (
↑↓) =git push/git pull
- Stage (
Best practices
Section titled “Best practices”- Always create a branch per feature (
feature/login,fix/bug). - Make frequent commits with clear messages.
- Use a
.gitignoreto skip unnecessary files. - Always pull before starting to code.