Skip to content

Lesson 1 of 6

Create the site and first commit

Build a one-page site and commit it to a new Git repository.

7 minDevOps

After this lesson you will be able to create a simple one-page website, start a Git repository for it, and make your first commit.

Create the project folder

Open a terminal and create a new folder for the site. Name it my-site.

mkdir my-site
cd my-site

This folder will hold all the files for your website and its version history.

Write the HTML page

Create a file called index.html inside the folder. This will be the home page of your site.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>My Site</title>
</head>
<body>
  <h1>Welcome to My Site</h1>
  <p>This is a simple static website.</p>
</body>
</html>

The page has a heading and a short paragraph. A static site means the server sends the same files to every visitor, with no code running on the server.

Start a Git repository

Git is a version control system. It records changes to your files so you can go back to earlier versions. To start tracking this folder, run:

git init

This creates a hidden folder called .git where Git stores its history. The command prints a message like Initialized empty Git repository in ....

Check the status

Before you commit, see what Git has noticed. Run:

git status

Git reports that index.html is untracked. That means Git sees the file but is not yet recording changes to it.

Stage the file

A commit is a snapshot of your project at a point in time. First you add the files you want in the snapshot. This is called staging.

git add index.html

Now run git status again. Git shows index.html under "Changes to be committed". The file is staged and ready.

Make the first commit

Create the commit with a short message that says what you did.

git commit -m "Add home page"

Git saves the snapshot and prints a summary: one file changed, with some insertions. Your project now has its first commit.

View the commit history

To see the commit you just made, run:

git log --oneline

You will see one line with a short commit hash and your message. The hash is a unique identifier for that commit.

Understanding the staging area

The staging area is a place where you build the next commit. You can add files one by one, or add several at once when you have more files. This lets you group related changes into one snapshot. When you run git commit, only the files you have staged go into that commit.

Ignoring files that should not be committed

Some files should not be tracked by Git. For example, your operating system may create hidden files like .DS_Store on macOS. To tell Git to ignore them, create a file called .gitignore in the project folder.

touch .gitignore

Open .gitignore in a text editor and add a line for each pattern to ignore. For instance:

.DS_Store
*.log

The first line ignores the macOS file, and the second ignores any file ending in .log. Now Git will not show these as untracked. For now, leave .gitignore untracked; you can commit it later if you want to share these rules.

Commit messages that help you later

A good commit message is short but specific. It says what changed and why. For example, "Add home page" is clear. A message like "Update stuff" is not. When you look back at your history, the messages tell the story of your project.

You now have a one-page site under version control. In the next lesson you will add a test that runs automatically after each commit.

Key takeaways

  • A Git repository tracks changes to files in a folder.
  • Use git add to stage files, then git commit to save a snapshot.
  • git status shows what is staged, modified, or untracked.
  • git log --oneline lists commits with short hashes and messages.
  • A .gitignore file tells Git which files to ignore.

Try it

Add a second page to the site. Create a file called about.html in the same folder, with a heading that says "About" and a short paragraph. Stage the file and commit it with the message "Add about page". Then run git log --oneline and check that you see two commits, with the newest one at the top.

Official documentation

Ready to use this in a job?

Rolebound applies to matching roles for you.

Start now

Written with AI and checked automatically. Tools change, so a command may behave differently in the version you install. Spotted a mistake? Tell us.

    Cookies on Rolebound

    We use necessary cookies to sign you in and keep the site working — those cannot be turned off. We would also like to set analytics and advertising cookies so we can see which pages help people get interviews and which adverts brought them here. Nothing optional is set unless you say yes, and you can change your mind at any time from “Cookie settings” in the footer. Read our Privacy Policy.