Skip to content
Back to Git and GitHub for Your Projects course

Work & Development · Web Development & Programming

Free preview

Start a local history you can inspect

Lesson 1 of Git and GitHub for Your Projects. Anyone can read this lesson with no account. Every lesson after this one is for students.

Track a useful history

Make a practice Git project, save two versions, and read its history.

After this lesson you will be able to create a Git repository, record your first commits and read them back from the history.

1Start with one idea

Git records a project’s history on your computer. A repository is the project plus its saved history. A commit is a recorded version of the files you selected, with a message saying what changed. Think of named checkpoints you can compare later. GitHub is an online service for sharing Git repositories.

2Build a safe practice repository

Git records versions of a project. A repository contains your working files and a hidden history directory called .git. A commit records selected file content, an author and a message. It does not automatically upload anything. Today you will create a throwaway local repository and make a first commit, then explain what changed.

Install Git from git-scm.com/downloads. On Windows, open Git Bash from the Start menu after installing Git. Use it for this course’s commands. They use the command language understood by Git Bash, not PowerShell. On a Mac, use Terminal; if git --version offers to install the command line developer tools, accept. You need Git 2.28 or newer. Check git --version first. Installation choices are documented at Git downloads; the official git init reference explains the initial branch option. Keep the practice folder separate from any real project.

3Worked example

Run these commands one at a time. The temporary path is different on each computer. The test identity is configured only inside this repository.

practice_dir=$(mktemp -d)
cd "$practice_dir"
git init -b main
git config user.name "Practice Student"
git config user.email "practice@example.invalid"
printf 'Community resource guide\n' > guide.txt
git status --short
git add guide.txt
git commit -m "Add the resource guide heading"
git log -1 --format=%s
git status --short

Before staging, short status shows ?? guide.txt: Git has not started tracking that file. After the commit, the log prints Add the resource guide heading. The final status prints nothing when your working tree is clean. Commit identifiers and the temporary folder name will vary; the message and recorded content should agree. Read the file with cat guide.txt and compare it with git show HEAD:guide.txt.

Keep three ideas separate:

  • The working tree is the copy of the files you can edit.
  • The staging area holds the selection for your next commit.
  • HEAD identifies the commit you currently have checked out, usually through your current branch.

Saving a file updates the working copy. git add stages the content you selected. git commit records that staged content in history. A commit is useful when its message describes the change.

4Your practice and debugging challenge

Add two resources below the heading, but stage only guide.txt. Make a second commit describing the addition. Then create a separate notes.txt file without staging it. Predict the next status output before checking. Write the two commit messages and explain why the untracked notes are absent from the second commit.

If Git says it cannot find a repository, run pwd and confirm you are inside the temporary folder. If it asks for an identity, inspect git config --local user.name and user.email. Do not fix a local exercise by changing your whole computer's identity unnecessarily.

5Check yourself

  1. Does a clean status mean your project is correct?
  2. Does a commit send your files to GitHub?
  3. Which command selected guide.txt for the commit?
Show answers
  1. No: it means Git detects no pending tracked changes or untracked files, not that the content meets the brief.
  2. No. A separate git push to a remote does that, as you will see in the GitHub lesson.
  3. git add guide.txt.

6Save your progress

Keep a practice journal recording your repository path, two meaningful commits and the contents of your guide. This local history becomes the starting point for the later branch and review exercises. Do not put personal records, passwords or private keys into it.

Continue with the full course

This free preview is lesson 1 only. Enroll to open the rest of Git and GitHub for Your Projects.