Skip to content

Version Control with GitHub

Learn to use Git and GitHub directly from Visual Studio Code by creating a web page and managing multilingual versions with branches.

Register your developer profile:

  1. Go to github.com and click Sign up.
  2. Enter your email address, create a secure password, and choose a username.
  3. Complete the verification and enter the confirmation code you received by email.

An essential prerequisite for managing files locally.

Download and install Git from the official website git-scm.com (you can accept the default options in the setup wizard).

Open the terminal (or the VS Code integrated terminal) and run the following commands, replacing the values with the information associated with your GitHub account:

Finestra del terminale
git config --global user.name "il mio username"
git config --global user.email "email@example.com"

Set up the initial file for the website:

  1. Open VS Code and create a new folder on your computer called my-first-repo.

  2. Open the folder in VS Code by selecting File > Open Folder….

  3. Create a new file called index.html and enter this starter code:

    index.html
    <!DOCTYPE html>
    <html lang="it">
    <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Mio Primo Progetto</title>
    </head>
    <body>
    <h1>Hello World</h1>
    </body>
    </html>

Stage, commit, and publish to the cloud. VS Code lets you manage the Git workflow using a fully graphical and intuitive interface:

  1. Click the Source Control icon in the left-hand sidebar (or use the shortcut Ctrl+Shift+G on Windows/Linux or Cmd+Shift+G on Mac).
  2. Click the Initialize Repository button.
  3. Stage your changes: Hover over index.html in the Changes list and click the + button (Stage Changes). The file will move to the Staged Changes section.
  4. Enter a commit message in the text field at the top (for example, First commit: Hello World) and click Commit.
  5. Click the Publish Branch button.
  6. If prompted, authorize VS Code to access your GitHub account and select Publish to GitHub public repository.

Working with Branches: Italian vs. English

Section titled “Working with Branches: Italian vs. English”

Complete workflow: Edit → Stage → Commit on different branches. Branches let you develop parallel features without affecting the main branch (main).

    • Click main in the VS Code status bar at the bottom left.
    • Select Create new branch…, enter italian-version, and press Enter.
    • In index.html, change the main text inside the <h1> tag:
    <h1>Hello World</h1>
    <h1>Ciao Mondo</h1>
    • Staging: In the Source Control view, click the + next to index.html to stage the change.
    • Commit & Publish: Enter the message Italian translation, click Commit, and then click Publish Branch.
    • Return to the main branch: click italian-version in the bottom-left corner and select main from the list. Notice that index.html returns to its initial version!
    • Create a new branch called english-version by following the same steps.
    • Add a detail in English to index.html:
    <h1>Hello World</h1>
    <p>Welcome to my first versioned website!</p>
    • Staging: Click the + button next to index.html to stage the changes.
    • Commit & Publish: Enter the message English version update, click Commit, and then click Publish Branch.

To see the real “magic” of Git and confirm that both versions coexist in the same project without overwriting each other, perform these checks:

  1. Click the branch name in the bottom-left corner of the VS Code status bar.
  2. Select italian-version: look at index.html in the editor and you will see the text “Ciao Mondo”.
  3. Click again and select english-version: the file will instantly change to show “Hello World” and the new paragraph.
  1. Open your repository page on github.com.
  2. Above the file list in the upper-left corner, click the dropdown labeled main (or Branches).
  3. Select italian-version or english-version to browse the branches: you will see the code in index.html change instantly depending on the selected branch!

Your answers to the quizzes on this page are saved in your browser's local storage and remain stored between visits.

What is the difference between Git and GitHub?

  • Git is an online service, while GitHub is the program installed on your computer.
  • Git is a version control system; GitHub is an online platform that hosts Git repositories.

    Correct: Git manages the project’s history, while GitHub lets you host and share repositories online.

  • They are two different names for the same tool.

What is staging used for before creating a commit?

  • To automatically publish all changes to GitHub.
  • To select the changes to include in the next commit.

    Correct: staging lets you choose which changes to save in the next revision.

  • To create a new branch without saving changes.

What does a commit record?

  • A public copy of the project on GitHub.
  • A revision of the selected changes, accompanied by a descriptive message.

    Correct: a commit saves the staged changes in the repository’s history.

  • Automatically switching from the current branch to main.

Why create a branch for an alternative version of the page?

  • To necessarily overwrite the contents of the main branch.
  • To work on a separate line of development without immediately changing other branches.

    Correct: each branch can contain a distinct version of the project, and you can switch between them.

  • To turn a local repository into a GitHub account.

What happens when you publish a branch?

  • The local branch is deleted after a commit is created.
  • The local branch is sent to the remote repository on GitHub.

    Correct: publishing makes the branch available in the remote repository as well.

  • All repository branches are merged automatically.

Quiz progress

0 / 0 questions answered (0%)

0 correct answers