Installing Git and Making Your First Commit

Install Git, configure your identity, initialize a project, and view commit history in VS Code.

🎯 Introduction

If you are new to version control, Git is an essential skill to learn. It helps you manage code versions, collaborate with others, and return to earlier code when something goes wrong. This article walks you through installation, initial configuration, and your first workflow, including how to view and manage commit history in VS Code.

This guide is for complete beginners and anyone who has started using Git but is still getting familiar with the workflow. We will cover installing Git, configuring your name and email, creating your first project, committing changes, and viewing history in VS Code. These steps give you a foundation for managing projects with Git.


🧩 Installing Git and setting up VS Code extensions

1. Install Git

Git runs on Windows, macOS, and Linux and is straightforward to install. On Windows:

  1. Visit the Git website at https://git-scm.com/ and download the installer for your operating system.
  2. Run the installer. The default options are recommended.
  3. After installation, open a command prompt (press Win + R and enter cmd), then run:
git --version

If a version number appears, Git is installed successfully.

On macOS, you can install Git with Homebrew:

brew install git

2. Git extensions for VS Code

VS Code includes built-in Git support, so you do not need an extension for basic Git features. Open them through the branch-shaped Source Control icon in the left sidebar.

Make sure VS Code is installed and reasonably up to date so its Git integration works correctly.

😊 Configuring your name and email: why it matters

Git records author information with each commit. Configure your name and email so others can identify who made a change.

Run these commands:

git config --global user.name "Your Name"
git config --global user.email "your_email@example.com"

These commands save your name and email in the global configuration file, making them the defaults for all your projects.

Why does this matter?

  • It makes commits from different developers easy to identify.
  • It helps teammates trace issues to the relevant changes and authors.
  • Many remote hosting platforms, such as GitHub, use this information to associate commits with user accounts.
To change your name or email later, run the same commands with new values. To configure them for a single project, omit --global.

🛠 Creating your first HTML project and initializing a Git repository

Let's create a simple HTML project and initialize a Git repository.

  1. Create a folder named my-first-git-project.
  2. Inside it, create an index.html file with some basic HTML:
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>My First Git Project</title>
    </head>
    <body>
        <h1>Welcome to My First Git Project</h1>
    </body>
</html>
  1. Open a terminal and change to that folder:
cd path/to/my-first-git-project
  1. Initialize the Git repository:
git init

This creates a hidden .git folder, marking the directory as a Git repository.


💾 Making your first commit

The basic Git workflow is “edit code → stage changes → commit”. Here are those steps in practice.

Initialize the repository

You already did this in the previous section, so you can skip this step.

`git init`

Add files to the staging area

git add index.html

This tells Git to include index.html in the next commit.

To add all files, use:

git add .

Commit the changes

git commit -m "Initial commit: add index.html"

Use the -m option to write a commit message describing the change so it is easy to review later.

Git saves the staged contents as a versioned snapshot.

Keep commit messages concise and specific so teammates can quickly understand the changes.

👀 Viewing Git commit history in VS Code (graphical interface)

VS Code makes it easy to browse Git history.

  1. Install the GitLens — Git supercharged extension.
  2. Click the Source Control icon in the left sidebar.
  3. Expand the GITLENS section to view commit history.
  4. Switch from Source Control to GitLens Inspect to view an individual file's history in FILE HISTORY.

❓ Knowledge check

Q1: Why use Git for version control?

Git records code history, making it easier to restore earlier versions, collaborate, and manage multiple versions while reducing code loss and helping resolve conflicts.

Q2: What is the difference between git add and git commit?

git add stages files for the next commit; git commit saves the staged contents as a versioned snapshot.

Q3: What if I make a mistake in a commit message?

Use git commit --amend to edit the most recent commit message. Use it carefully if the commit has already been pushed to a remote repository.


🧪 Exercises

Exercise 1: Initialize a Git repository and make a commit

Create a folder and a simple hello.html file, initialize a Git repository, then stage and commit the file.

mkdir git-practice
cd git-practice
echo "<h1>Hello Git!</h1>" > hello.html
git init
git add hello.html
git commit -m "Add hello.html"

Exercise 2: View commit history in VS Code

Open the project folder from the previous exercise in VS Code, click Source Control in the left sidebar, and view the commit history.


🎉 You now know how to install and configure Git, initialize a repository, make commits, and view history in VS Code! Put these skills to work in your projects to keep improving your development workflow.