Learn

Your first commit

Git

git init, add, commit, status, log: the basic workflow you will repeat a thousand times.

Prerequisites

Five commands are enough for your daily Git work: init, status, add, commit, log. This lesson walks you through each one on a real folder.

Create a new repo

Create a folder and navigate into it, then:

shell
mkdir mon-projet
cd mon-projet
git init

You will see a message like Initialized empty Git repository in .../.git/. Git just created a hidden .git/ folder at the root. That is where all your history will be stored. Never delete it by hand: you would lose the entire history.

Check the status

At any point, you can ask Git where things stand.

shell
git status

For now, the repo is empty. Create a file to have something to commit:

shell
echo "Hello Git" > README.md
git status

This time, git status shows README.md listed under "Untracked files". Git sees the file but is not tracking it yet.

Stage the file

To prepare the file for a commit, you put it in the staging area.

shell
git add README.md
git status

Now README.md appears under "Changes to be committed". It is ready to be recorded in history.

Commit

shell
git commit -m "premier commit : ajout du README"

You will see a message like [main (root-commit) a3f5b6c] premier commit.... Your first snapshot is in. The a3f5b6c is the unique identifier for this commit.

View the history

shell
git log

You see your commit, with its full hash, your name, your email, the date, and the message. Press q to exit.

For a more compact format:

shell
git log --oneline

The workflow you will repeat

For each change you make after this, the cycle is the same:

  1. Edit your files.
  2. git status to see what changed.
  3. git add <files> to stage the changes to commit.
  4. git commit -m "message" to record them.

And from time to time, git log --oneline to check where you are.

.gitignore: what Git should ignore

You do not want to commit your node_modules/ folder, your .env files, or generated builds. Create a .gitignore file at the root and list the patterns to ignore.

shell
echo "node_modules/
.env
dist/
.DS_Store" > .gitignore
git add .gitignore
git commit -m "ajoute .gitignore"

From now on, Git will never show those files in git status again.

What comes next

The next lesson connects you to GitHub to publish your repo and work from multiple machines.

Check off steps to unlock what comes next

Back to course