Getting Started with
Git & GitHub
A step-by-step guide to setting up version control on your computer and connecting it to GitHub, so you can save, share, and collaborate on your code.
Create a GitHub Account
GitHub is the online platform where your code is stored and shared. You will need a free account before doing anything else.
Go to github.com and click Sign up.
Enter your email address, create a password, and choose a username.
Tip: Choose a username that looks professional — it will appear on all your projects. For example, john-doe is better than j0hnd0e99.
Complete the short verification puzzle, then click Create account.
Check your email inbox for a verification code from GitHub, enter it on the page, and your account is ready.
Download & Install Git
Git is the version control software that runs on your computer. You need to install it before VS Code can use it.
Go to git-scm.com/download/win. The download should start automatically.
Run the installer (.exe file). Click Next through all the steps — the default settings are fine.
On the screen titled "Choosing the default editor", select Visual Studio Code from the dropdown if it is available.
Once installed, open a new terminal in VS Code (Ctrl + `) and run the following to confirm Git is installed:
git --version
You should see something like git version 2.x.x.windows.x.
Open the terminal in VS Code (Ctrl + `) and run:
git --version
If Git is not installed, macOS will prompt you to install the Xcode Command Line Tools. Click Install and wait for it to finish.
Alternatively, if you have Homebrew installed, you can run brew install git.
Run git --version again to confirm the installation was successful.
Configure Git & Set Up SSH
In this step you will tell Git who you are, and then set up a secure SSH connection so that your computer can communicate with GitHub without requiring a password each time.
Git attaches your name and email to every change you save. This is how your contributions are recorded on GitHub.
Important: Use the same email address as your GitHub account, otherwise GitHub will not link your work to your profile.
Open the terminal in VS Code (Ctrl + `) and run these two commands. Replace the placeholder text with your actual details.
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
Verify that both values were saved correctly:
git config --list
You should see user.name and user.email listed in the output.
SSH is a secure method that lets your computer communicate with GitHub without entering your password every time you upload or download code. You will create a key pair: a private key that stays on your computer, and a public key that you give to GitHub.
Think of it like a padlock and key. You give GitHub the padlock (public key) — only your key (private key) can open it. You never share the private key with anyone.
Generate your SSH key pair. Run this command in your VS Code terminal:
ssh-keygen -t ed25519 -C "[email protected]"
Replace [email protected] with your GitHub email. The terminal will ask you three questions — press Enter each time to accept the default answers.
After running this, two files are created in a hidden folder on your computer called .ssh: your private key (id_ed25519) and your public key (id_ed25519.pub). The .pub file is the one you will share with GitHub.
Copy your public key to the clipboard.
cat ~/.ssh/id_ed25519.pub | clip
This copies your public key to the clipboard automatically.
pbcopy < ~/.ssh/id_ed25519.pub
This copies your public key to the clipboard automatically.
Add your public key to GitHub.
- Go to github.com/settings/keys.
- Click New SSH key.
- In the Title field, type a name for this computer (e.g.,
My Laptop). - In the Key field, paste what you copied in the previous step (Ctrl + V).
- Click Add SSH key.
Test the connection. Run this in your terminal:
ssh -T [email protected]
If everything is set up correctly, you will see:
Hi your-username! You've successfully authenticated, but GitHub does not provide shell access.
If asked "Are you sure you want to continue connecting (yes/no)?", type yes and press Enter. This message appears only the very first time.
Install VS Code Extensions for Git
VS Code has basic Git support built in, but the following extensions make it significantly easier to work with GitHub. Think of extensions as add-ons that give VS Code extra abilities.
How to Install an Extension
Open the Extensions panel by clicking the four-square icon in the left sidebar, or press Ctrl + Shift + X.
In the search bar at the top, type the name of the extension (e.g., GitHub Pull Requests).
Click the result that shows the correct publisher name (e.g., GitHub), then click the blue Install button.
Check the publisher name! There may be several extensions with similar names. Always verify the author matches the one listed above.
VS Code may show a prompt to Sign in to GitHub. Click Allow — a browser window will open. Sign in with your GitHub credentials and click Authorise Visual-Studio-Code, then switch back to VS Code.
You only need to sign in once. VS Code will remember your GitHub account on this computer for all future sessions.
Essential Terminal Commands
The terminal (also called the command line) lets you control your computer by typing commands. Before you start working with Git, it helps to know a few basic commands for moving between folders and checking where you are.
To open the terminal in VS Code, press Ctrl + ` (the backtick key, just below Esc). You can also go to Terminal → New Terminal from the menu bar.
Navigating Folders
When you open a terminal, you always start in a specific location on your computer — like standing inside a particular folder. These commands help you move around.
pwddir Windows
lscd Desktop..) always mean "go up one folder".cd ..mkdir ProjectsclearNavigating to a Folder — Worked Example
Suppose you want to save a project inside a folder called Projects on your Desktop. Here is how you would get there:
Handy shortcuts to know:
Press Tab to auto-complete a folder name — start typing and press Tab to fill in the rest.
Press ↑ to go back to the last command you typed, so you do not have to retype it.
Opening a Folder in VS Code from the Terminal
Once you have navigated to a folder, you can open it directly in VS Code with a single command:
# The dot ( . ) means "the folder I am currently in"
code .
If code . does not work on macOS, open VS Code, press Ctrl + Shift + P, type shell command, and select Install 'code' command in PATH. Then try again.
Create a Repository
A repository (or "repo") is a folder where Git tracks all changes to your project. There are two ways to create one.
Use this method when you want to start a project on GitHub first, then download it to your computer.
Log in to github.com. Click the + icon in the top-right corner, then select New repository.
Fill in the repository details:
- Repository name — use lowercase letters and hyphens (e.g.,
my-first-project). Avoid spaces. - Description — a short sentence describing the project (optional but recommended).
- Visibility — choose Public so others can see it, or Private to keep it to yourself.
Tick Add a README file, then click Create repository. Your repository is now live on GitHub.
A README.md file is the front page of your repository. It is a good place to describe what your project does.
Create a folder on your computer and open it in VS Code.
Before downloading your repository, first decide where you want to keep your projects. For example, you might create a folder called Projects on your Desktop using File Explorer (Windows) or Finder (macOS).
Once the folder exists, open it in VS Code:
- In VS Code, go to File → Open Folder…
- Navigate to and select the folder you just created.
- Click Open.
Why open the folder first? When you open a folder in VS Code and then launch the terminal (Ctrl + `), the terminal automatically starts inside that folder. This means you do not need to type any cd commands — VS Code handles the location for you.
Copy the SSH URL from GitHub.
Go back to your repository page on GitHub. Click the green Code button, select the SSH tab, and copy the URL. It will look like this:
[email protected]:your-username/your-repo-name.git
Open the terminal and clone the repository.
In VS Code, press Ctrl + ` to open the terminal. Because you opened the Projects folder in the previous step, the terminal is already pointing to that location.
Run the following command, replacing the URL with the one you copied:
git clone [email protected]:your-username/your-repo-name.git
Git will download all the files from GitHub and create a new subfolder with your repository name inside your Projects folder.
Open the downloaded repository in VS Code.
After cloning, go to File → Open Folder…, navigate into the new folder that Git created (e.g., my-first-project), and click Open.
VS Code will reload with your repository open. You are now ready to start coding!
You can confirm you are in the right place by looking at the folder name shown in the Explorer panel on the left — it should match your repository name.
Use this method when you already have a project folder on your computer and want to publish it to GitHub.
Open your project folder in VS Code: go to File → Open Folder… and select your project.
Click the Source Control icon in the left sidebar (it looks like a branching tree), or press Ctrl + Shift + G.
Click Initialise Repository. This turns your folder into a Git repository.
All your files will appear under Changes. Type a short message in the text box at the top (e.g., Initial commit) and click the ✓ Commit button.
A commit is a saved snapshot of your project at a specific point in time. Always write a clear, descriptive message so you can identify it later.
Click Publish Branch. VS Code will ask whether to publish it as Public or Private on GitHub — choose your preference.
If you have not already signed in to GitHub from VS Code, a browser window will open asking you to authorise the connection. Sign in and click Authorise Visual-Studio-Code, then switch back to VS Code. Your repository will then appear on GitHub automatically.
You can click the link that appears in VS Code's bottom status bar to open your new repository in the browser straight away.
Everyday Git Commands
Once your repository is set up, these are the three commands you will use most often:
# Stage all your changed files, ready to be saved
git add .
# Save a snapshot of your project with a descriptive message
git commit -m "Describe what you changed"
# Upload your latest commits to GitHub
git push
Understanding Changes
Before saving your work, it helps to understand how Git thinks about the files in your project. Git puts every file into one of three states at any given time.
The Three States Explained
Untracked U — A brand-new file that Git has not seen before. Git knows the file exists, but it is not watching it yet. In VS Code's Source Control panel, these files show a U badge next to them.
Modified (tracked) M — A file that Git was already watching, but you have made changes to it since the last commit. Git has noticed the difference. These appear with an M badge in VS Code.
Staged A — A file you have told Git to include in the next commit. Think of staging as placing items into a box before sealing and labelling it. Only staged files get included in your next commit.
You do not have to stage every file at once. If you changed five files but only want to save three of them in this commit, you can stage only those three. The other two will remain in your working directory for the next commit.
Checking the Status of Your Files
At any time, you can run this command in the terminal to see which files are untracked, modified, or staged:
git status
Stage, Commit & Push
Once you have made changes to your project, there are three actions you will perform regularly: stage your files, commit them with a message, and push them to GitHub. You can do all of this either through VS Code's Source Control panel or the terminal.
Open the Source Control panel. Click the branching-tree icon in the left sidebar, or press Ctrl + Shift + G. You will see all changed files listed under Changes.
Stage your files. Hover over a file name and click the + icon that appears to stage that individual file. To stage all changed files at once, hover over the Changes heading and click the + icon there instead. Staged files move to a section labelled Staged Changes.
You can also right-click a file and choose Stage Changes from the menu.
Write a commit message. Click the text box at the top of the panel that says Message and type a short, clear description of what you changed — for example, Add player movement function.
A good commit message answers: "What does this change do?" Use the present tense. For example, Fix login bug rather than Fixed login bug.
Commit. Click the ✓ Commit button. Your changes are now saved as a snapshot in your local repository.
Push to GitHub. After committing, VS Code will show a Sync Changes button (or a Push option in the … menu). Click it to upload your commit to GitHub.
You can also click the small cloud/sync icon in VS Code's bottom status bar to push.
Run these three commands in order each time you want to save and upload your work.
# 1. Stage all changed files
git add .
# 1b. To stage a specific file only:
git add filename.py
# 2. Commit with a message
git commit -m "Add player movement function"
# 3. Push to GitHub
git push
Pulling Changes from GitHub
If you are working on multiple computers, or collaborating with others, you should always pull the latest changes from GitHub before you start working. This downloads any new commits that are on GitHub but not yet on your computer.
git pull
Always pull before you push. If someone else has pushed changes since you last pulled, your push may be rejected. Run git pull first, resolve any conflicts, then push.
Undoing Changes
One of the most useful things about Git is that you can always go back. There are three different situations you might find yourself in, each with a different solution.
You have made changes to a file but have not committed them yet, and you want to throw those changes away and restore the file to how it was in the last commit.
In the Source Control panel, right-click the file you want to restore and select Discard Changes. The file will revert immediately to its last committed state.
This action is permanent — discarded changes cannot be recovered. Make sure you no longer need them before proceeding.
# Discard changes in a specific file
git restore filename.py
# Discard ALL uncommitted changes in the entire project
git restore .
You have committed your changes but have not pushed them to GitHub yet, and you want to undo that commit. Your file edits are kept — only the commit is undone.
# Undo the last commit; your changes remain in the working directory
git reset --soft HEAD~1
HEAD~1 means "one commit before where I am now". Your files stay exactly as they are — only the commit wrapper is removed. You can edit further and recommit.
You have already pushed a commit to GitHub and want to undo it. Because others may have already pulled your changes, you should not rewrite history — instead, use git revert, which creates a new commit that undoes the previous one safely.
First, find the ID (hash) of the commit you want to undo:
git log --oneline
You will see a list of recent commits, each with a short ID (e.g., a3f9c12) and its message. Copy the ID of the commit you want to undo.
Run the revert command with that ID:
git revert a3f9c12
Git will create a new commit that cancels out the changes from that commit. Push this new commit to GitHub as usual.
In VS Code, you can also view the commit history using the GitLens extension: open the Source Control panel, click GitLens in the sidebar, and browse the timeline to find the commit you need.
Main vs. Branch
When you create a repository, Git creates a default timeline for your project called main. Every commit you make goes onto this timeline in order. Branches let you create a parallel copy of that timeline so you can experiment or add features without affecting the main version.
🌿 main branch
- The primary, stable version of your project
- Should always contain working, tested code
- What users or teammates see when they look at your repo
- You should not commit experimental or broken code directly to main
🔀 Feature branch
- A separate copy of the project created for a specific task
- Safe to experiment — changes do not affect main
- Once the work is complete and tested, it is merged back into main
- Can be deleted after merging
A Visual Example
Imagine you are building a game. Your main branch has the working game. You create a branch called add-scoreboard to build a new feature. While you work on it, main stays untouched. When the scoreboard is ready, you merge it in.
You can have as many branches as you like at the same time. A common approach is to create one branch per feature or bug fix, then merge it when it is done.
Creating a Branch
You can create and switch between branches either from VS Code or the terminal. When you create a branch, Git takes a copy of the current state of your project and gives that copy a new name.
Look at the bottom-left corner of VS Code. You will see the current branch name (e.g., ⎇ main). Click on it.
A dropdown menu will appear at the top. Select Create new branch…
Type a name for your new branch and press Enter. Use lowercase letters and hyphens to describe the task (e.g., add-scoreboard).
VS Code will switch to the new branch immediately. You can confirm this by checking the branch name shown in the bottom-left corner — it should now show your new branch name.
Make your changes, then stage and commit them as you learnt in Step 8. When you push for the first time on a new branch, VS Code will ask you to Publish Branch — click it to create this branch on GitHub as well.
# Create a new branch and switch to it immediately
git checkout -b add-scoreboard
# Check which branch you are currently on
git branch
# Switch to a different branch that already exists
git checkout main
# After committing, push the new branch to GitHub
git push --set-upstream origin add-scoreboard
You only need --set-upstream origin branch-name the first time you push a new branch. After that, git push is enough.
Pull Requests & Merging
Once your work on a branch is complete, the next step is to merge it back into main. On GitHub, this is done through a Pull Request (PR) — a proposal to merge your branch that can be reviewed and discussed before it is accepted.
After pushing your branch to GitHub, go to your repository page. GitHub will usually show a yellow banner saying "Your branch had recent pushes" with a Compare & pull request button. Click it.
On the Pull Request page, fill in a title and a description explaining what this branch does and why it should be merged.
At the top of the page, confirm the arrows show the correct direction: add-scoreboard → main. You are merging your branch into main, not the other way around.
Click Create pull request. The PR is now open and can be reviewed.
In the PR, click the Files changed tab to see exactly what was added, removed, or modified. Lines in green are additions; lines in red are deletions.
Reviewers can click on any line to leave a comment. If you are working alone, you can review your own changes here before merging as a final check.
Once satisfied, click Review changes → Approve (if you are a reviewer), then go back to the Conversation tab.
Click Merge pull request, then Confirm merge. Your branch is now merged into main.
Click Delete branch to remove the feature branch from GitHub — it is no longer needed now that the work is merged.
After merging, switch back to main on your computer and pull the latest changes so your local copy is up to date:
git checkout main
git pull
If you merged something that broke the project, you can revert the merge commit on GitHub directly, or use the terminal.
Via GitHub (easiest): Go to the closed Pull Request on GitHub. At the bottom, GitHub shows a Revert button. Click it — GitHub will automatically create a new PR that undoes the merge. Merge that new PR to restore the previous state.
Via terminal: Find the merge commit ID with git log --oneline, then revert it:
# Revert a merge commit — the -m 1 flag tells Git to keep the main branch side
git revert -m 1 <merge-commit-id>
git push
Collaborating on GitHub
GitHub is built for teamwork. When multiple people work on the same repository, a few extra concepts and habits become important.
On your repository page, go to Settings → Collaborators.
Click Add people and search for your teammate's GitHub username. They will receive an email invitation and will need to accept it before they can push changes.
When working with teammates, everyone follows the same pattern to avoid overwriting each other's work:
🔄 Before you start
Always pull the latest changes from main before creating a branch or starting new work. This ensures you are building on the most recent version.
git checkout main
git pull
🌿 While you work
Always work on a dedicated branch, never directly on main. Push your branch regularly so your teammates can see your progress and so your work is backed up on GitHub.
git checkout -b your-feature
# ... make changes, stage, commit ...
git push
A merge conflict happens when two people edit the same part of the same file. Git does not know which version to keep, so it asks you to decide.
When a conflict occurs during a pull or merge, Git marks the affected file with special symbols:
<<<<<<< HEAD
score = 0 ← your version
=======
score = 10 ← teammate's version
>>>>>>> main
In VS Code, conflicted files are highlighted. VS Code will show buttons above the conflict: Accept Current Change, Accept Incoming Change, or Accept Both Changes. Click the one that reflects the correct version, or edit the file manually to combine both changes.
After resolving all conflicts, stage and commit the resolved file:
git add .
git commit -m "Resolve merge conflict in score.py"
git push
The best way to avoid merge conflicts is for each teammate to work on different files or different sections of the project. Communicate with your team about who is working on what before you start.
You may encounter these two terms when working with other people's repositories on GitHub.
📥 Clone
Downloads a copy of a repository to your computer. You use this for repositories you are a collaborator on — you can push changes back to the original.
🍴 Fork
Creates your own personal copy of someone else's repository on GitHub. You use this when you are not a collaborator. Changes you make stay in your fork until you open a PR to the original repo.