What you need

  • Computer and internet: a laptop or desktop and a stable connection
  • System: Windows 10 or 11, macOS or Linux
  • Tools: Git (search for "Git official download") and a code editor such as Visual Studio Code (search for "VS Code official download")

Download only from each tool's official site and check the address before installing.

What you will learn

You will install and set up Git, turn a folder into a repository, and save your first commit. You will also learn the one habit that protects you from the most common, most expensive beginner mistake: committing a password.

You need a computer and about 30 minutes. No coding knowledge is needed. Every command has a Copy button: copy it, paste it into your terminal, press Enter.

Ewoi

Git feels strange for the first week and natural forever after. Everyone you admire went through that first week too.

Why Git exists

Imagine writing an essay and saving it as essay.docx, then essay-final.docx, then essay-final-v2.docx, then essay-final-REALLY-final.docx. You lose track of what changed, when, and why. Now imagine three people editing it at once.

Git solves this. It keeps a complete history of your project as a series of snapshots. Each snapshot (a commit) records exactly what every file looked like, who saved it, when, and a short message saying why. You can look back at any snapshot, compare two of them, or undo a change, at any time.

Almost every software team in the world uses Git. Learning it is not optional for a developer; it is like learning to save your work.

Three words to know first

Word Meaning Everyday picture
Repository A folder Git is watching, with its full history A photo album
Commit One saved snapshot, with a message One photo with a caption
Staging area The changes you have picked for the next commit Photos you have chosen to print next

Step 1: Install Git

Check if Git is already installed. Open a terminal and run:

git --version

If you see something like git version 2.47.0, you are ready; skip to Step 2. Any version from 2.28 up works with this lesson. If you see "command not found" or "not recognised", install it:

  • Windows: download the installer from the official site, git-scm.com, and accept the default options. It also installs Git Bash, a terminal that understands every command in these lessons. On Windows, use Git Bash (search for it in the Start menu) for this lesson and the ones after it.
  • macOS: run git --version once; macOS offers to install the developer tools that include Git. Click Install.
  • Ubuntu or Debian Linux: run sudo apt update then sudo apt install git.

Close the terminal, open a new one, and run git --version again to confirm.

Ewoi

Only download tools from their official website. Typing "download git" into a search engine sometimes shows lookalike sites first.

Step 2: Tell Git who you are (once per computer)

Every commit records an author. Set your name and email once:

git config --global user.name "Your Name"
git config --global user.email "[email protected]"

Use the same email you use (or will use) on GitHub, so your commits link to your profile.

Now one more setting. For historical reasons, Git currently calls the first branch master, while GitHub and most teams use main. The Git project has announced that Git 3.0 will switch the default to main; until then, set it yourself:

git config --global init.defaultBranch main

Check your settings any time with:

git config --global --list
What does --global mean?It saves the setting for every project on this computer. Without it, the setting applies only to the project you are inside.

Step 3: Create a project and turn it into a repository

Make a folder for this course and move into it:

mkdir -p ~/ewoi-learning/first-app
cd ~/ewoi-learning/first-app

mkdir -p makes the folder (and any missing parent folders). cd moves you into it. The ~ means your home folder.

Now tell Git to start watching this folder:

git init

You will see Initialized empty Git repository in .../first-app/.git/. Git created a hidden folder named .git. That folder is the whole history. You never need to open it, and you should never delete it. Stay in ~/ewoi-learning/first-app for the rest of this lesson: every command below runs there.

Step 4: Keep secrets out, before anything else

A secret is any password, API key or token that gives access to something. Real projects have them: a database password, a payment provider key, an email service key.

Here is the trap: once a secret is committed and pushed to GitHub, deleting it in a later commit does not remove it. The history keeps every old version, and automated bots scan public repositories for leaked keys within minutes. If it happens, you must change (rotate) the secret immediately.

The protection is a file named .gitignore. It lists files and folders Git must never track. Professionals create it before the first commit, so nothing secret can slip into history even once. Create it now:

printf ".env\nnode_modules/\nvendor/\n" > .gitignore
cat .gitignore

printf writes the three lines into the file (\n means "new line"), > sends them into a file instead of the screen, and cat shows the file so you can check it. You should see:

.env
node_modules/
vendor/
Line What it ignores Why
.env The file where projects keep their real secrets Secrets never belong in history
node_modules/ Downloaded JavaScript packages Huge, and anyone can re-download them
vendor/ Downloaded PHP packages Same reason

Professional projects also commit a file named .env.example that lists the setting names with fake placeholder values, so a teammate knows what to fill in without ever seeing your real secrets.

Step 5: Check the status

Now ask Git what it sees:

git status

You will see:

On branch main

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	.gitignore

nothing added to commit but untracked files present (use "git add" to track)

.gitignore is listed under Untracked files, in red. Untracked means: "this file exists, but I am not keeping history for it yet".

Ewoi

Run git status whenever you feel lost. It never changes anything; it only tells you where you are.

Step 6: Stage the file

Choose the file for your next snapshot:

git add .gitignore
git status

The file moves to Changes to be committed, in green, shown as new file: .gitignore. It is now in the staging area.

Why not save straight away? Because the staging area lets you choose. If you changed five files but only three belong together, you stage those three, commit them with a clear message, then commit the other two separately. Small, focused commits are much easier to understand and undo later.

Step 7: Commit

Save the snapshot with a message:

git commit -m "Ignore secrets and downloaded packages"

-m means "message", and the text in quotes is that message. Git replies with a short summary:

[main (root-commit) 892828d] Ignore secrets and downloaded packages
 1 file changed, 3 insertions(+)
 create mode 100644 .gitignore

892828d is a short ID (yours will differ). That ID is your commit's unique name. "root-commit" means it is the very first commit in this repository, and 3 insertions(+) counts the three lines you added.

Ewoi

Make .gitignore your first commit in every new project. It costs ten seconds and can save you a very bad day.

Step 8: Add a README with the same loop

A README is the front page of a project: what it is and how to use it. Create one, then stage and commit it exactly as before:

echo "# My first app" > README.md
git add README.md
git commit -m "Add a README"

echo prints text, and > sends it into a file. This time the summary has no "root-commit", because history already exists:

[main 69b0b34] Add a README
 1 file changed, 1 insertion(+)
 create mode 100644 README.md

See your history:

git log --oneline

One line per commit, newest first:

69b0b34 Add a README
892828d Ignore secrets and downloaded packages

Congratulations: you have a project with history.

Writing good commit messages

Your future self (and your teammates) will read these messages when something breaks. A simple rule: the message should complete the sentence "If applied, this commit will..."

Weak Strong
stuff Add contact form
fix Fix price rounding on the checkout page
changes Update README with setup steps
asdf Remove unused images

Keep the first line under about 50 characters, start with a verb, and describe what changed. If you need to explain why, add more lines in a longer message (run git commit without -m and an editor opens).

Ask your AI assistant

Here is what I changed in my project: [describe the change in plain words]. Suggest three short commit messages that complete the sentence "If applied, this commit will...", and tell me which is best and why.

What just happened (the full picture)

Every change you make follows the same loop:

  1. Edit files in your folder (your working directory).
  2. Stage the changes you want with git add.
  3. Commit them with git commit -m "message".
  4. Check where you are any time with git status, and look back with git log --oneline.

Common beginner mistakes

Problem What it means Fix
fatal: not a git repository You are in a folder Git is not watching cd into your project folder, or run git init if it is a new project
Please tell me who you are Step 2 was skipped Run the two git config --global commands
nothing to commit, working tree clean Nothing changed since your last commit Not an error. Change a file first
You ran git add . and staged too much . means "everything here" git restore --staged filename unstages one file. Before your very first commit, use git rm --cached filename instead (it keeps the file on disk)

Ask your AI assistant

I am learning Git. I ran this command: [paste the command] and got this message: [paste the full message]. Explain in simple words what it means and what I should run next. Do not assume I know Git terms.

Recap

  • Git keeps a history of your project as snapshots called commits.
  • git init starts a repository; the history lives in the hidden .git folder.
  • The loop is: edit, git add, git commit -m "...".
  • git status tells you where you are; git log --oneline shows history.
  • A .gitignore keeps secrets and downloaded packages out of history. Make it your first commit, before any other file.

Your practice task

In ~/ewoi-learning/first-app, make three more commits. Try each one yourself first, then compare with the commands:

  1. Add a second line to README.md describing what the app will do, and commit it with the message Describe the app in the README. Use a double >>, which adds to the end of the file instead of replacing it.
  2. Create notes.txt with one thing you learned and commit it with the message Add learning notes.
  3. Add a second line to notes.txt and commit it with the message Add a note about git status.
echo "A small app to learn Git." >> README.md
git add README.md
git commit -m "Describe the app in the README"
echo "Git saves snapshots called commits." > notes.txt
git add notes.txt
git commit -m "Add learning notes"
echo "git status shows where I am." >> notes.txt
git add notes.txt
git commit -m "Add a note about git status"

Then run git log --oneline. You should see five commits, newest first (your IDs will differ):

25c155f Add a note about git status
dde06fc Add learning notes
c73994e Describe the app in the README
69b0b34 Add a README
892828d Ignore secrets and downloaded packages

Run git status one last time. nothing to commit, working tree clean means everything is saved. Your project now looks like this (.git is hidden):

first-app/
├── .gitignore
├── README.md
└── notes.txt

The next lesson, Branches without fear, continues in this same folder.

Ask your AI assistant

I am a Git beginner. Here is my git log --oneline: [paste it]. Check whether my commit messages follow the "If applied, this commit will..." rule, and suggest a better wording for any that do not.

Check your understanding

1. What does git add do?

git add chooses what goes into the next snapshot. git commit saves the snapshot. Uploading to GitHub is a separate step called push.

2. You committed a password and pushed it to GitHub, then deleted it in a new commit. Is it safe now?

Git keeps every old version. Treat any pushed secret as leaked and rotate it. Private repositories still get shared, cloned and copied.

3. Which commit message is the most useful?

A good message completes "If applied, this commit will..." and says what changed, so anyone can understand it months later.

4. What file stops Git from tracking files such as .env?

.gitignore lists files and folders Git must never track. The .git folder is where the history itself lives.

5. When is the best time to add .gitignore to a new project?

A secret committed even once stays in history. Ignoring .env from the first commit means it can never slip in, and nothing needs cleaning up later.

Get the code on GitHub

Found this useful?

Every lesson stays free. Tap the thumbs up so we know what works, or say thanks with a soda or a coffee: it pays for hosting and new lessons.

Buy me a sodaBuy me a coffee

Want more on this?

Tell us which part was not clear, ask for a follow-up lesson, or request a lesson on any topic. We read every request.

I would like
Only to tell you when it is ready.

WhatsApp

Join the channelChat with us

Free lessons and updates in the channel. Questions about learning or training? Chat with us.