git init, add and commit: Create Your First Git Repository

Time to use Git for real. In this lesson you will turn a folder into a repository and make your first commits, learning the four commands you will use every day: git init, git status, git add and git commit.

Advertisement

πŸ“– What You’ll Learn: git init and the .git folder, reading git status, untracked vs staged files, the ways to use git add, git commit -m and -am, viewing history with git log –oneline, and writing good commit messages.


🎯 What You Will Build

In this lesson you will turn an ordinary folder into a Git repository and save your first snapshots (commits). By the end you will know the four commands you will use every single day: git init, git status, git add and git commit.

Make sure Git is installed and configured with your name and email.


πŸ“ Step 1: Create a Project Folder

mkdir qa-notes
cd qa-notes

🧱 Step 2: Initialize the Repository with git init

git init
Initialized empty Git repository in C:/Users/asha/qa-notes/.git/

git init creates a hidden .git folder. That folder is the repository: it stores every commit, branch and setting. Your files stay where they are; Git simply starts watching the folder.

⚠️ Common mistake: Never delete or edit the .git folder by hand. Deleting it removes the entire history of the project.


πŸ” Step 3: Check the State with git status

git status
On branch main

No commits yet

nothing to commit (create/copy files and use "git add" to track)

git status is your best friend. Run it before and after every command; it tells you exactly what Git sees and usually suggests the next command.


✍️ Step 4: Create a File

Create README.md with any editor, or from the terminal:

echo "# QA Notes" > README.md
git status
On branch main

No commits yet

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

Untracked means Git sees the file but is not managing it yet.


βž• Step 5: Stage the File with git add

git add README.md
git status
Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
	new file:   README.md

The file is now staged: it is in the list of changes that will go into the next commit. Common ways to stage:

CommandStages
git add README.mdOne file
git add docs/Everything in a folder
git add .All changes in the current folder and below
git add -AAll changes in the whole repository, including deletions
git add -pPieces of files, interactively (great for clean commits)

πŸ’Ύ Step 6: Save a Snapshot with git commit

git commit -m "Add README with project title"
[main (root-commit) 3f2a91c] Add README with project title
 1 file changed, 1 insertion(+)
 create mode 100644 README.md

You just made your first commit. 3f2a91c is the start of the commit’s unique ID (hash). Run git status again and you will see “nothing to commit, working tree clean”.


πŸ” Step 7: The Everyday Loop

Make a second change and commit it:

echo "- Learn Git basics" >> README.md
echo "Smoke tests: login, search, checkout" > test-plan.txt
git status
git add README.md test-plan.txt
git commit -m "Add learning goals and initial test plan"

See your history:

git log --oneline
8b1d4e2 (HEAD -> main) Add learning goals and initial test plan
3f2a91c Add README with project title

This edit, add, commit loop is 80% of daily Git work. Viewing history in detail is covered in git log and diff.


⚑ Shortcut: git commit -am

For files Git already tracks, you can stage and commit in one step:

git commit -am "Update test plan with API tests"

πŸ“ Note: -a does not include new (untracked) files. Use git add for those first.


✍️ Writing Good Commit Messages

A commit message is a note to your future self and your team.

❌ Avoidβœ… Prefer
updateAdd login tests for locked-out users
fixFix flaky checkout test by waiting for the API response
changesRename test data files to match feature names

Rules of thumb: start with a verb in the imperative (“Add”, “Fix”, “Remove”), keep the first line under about 50 characters, and describe what and why, not how. The full conventions are in commit messages and Conventional Commits.


🧭 What Happened Behind the Scenes?

Working directory  ──git add──▢  Staging area  ──git commit──▢  Repository (.git)
   (your files)                (next snapshot)               (saved history)

These three areas are the heart of Git. The next lesson explains them in detail.


πŸ“ Assignment

  1. Create a folder git-practice, run git init and check git status.
  2. Create README.md and notes.txt, stage only README.md, and commit it. Run git status and explain why notes.txt is still untracked.
  3. Stage and commit notes.txt with a good commit message.
  4. Make three more small commits, then run git log --oneline.
  5. Edit a tracked file and commit it with git commit -am.
  6. Bonus: create two changes in one file and use git add -p to commit only one of them.

❓ FAQ

πŸ€” What does git init do?

It creates a hidden .git folder that turns the current folder into a Git repository, so Git can start tracking changes.

πŸ€” What is the difference between git add and git commit?

git add chooses which changes go into the next snapshot (staging). git commit saves the staged changes permanently in the repository history with a message.

πŸ€” What does git add . do?

It stages all new, modified and deleted files in the current folder and its subfolders.

πŸ€” How do I commit with a message in Git?

git commit -m "Your message". Without -m, Git opens your configured editor to write the message.

πŸ€” Why does Git say “Please tell me who you are”?

Your name and email are not configured. Run the commands from Configure Git, then commit again.


🎯 Next Steps

🎬 Learn Git and GitHub step by step: watch the series on YouTube!

Subscribe to SqaToolsByDY • Practice on sqatools.in

6 thoughts on “git init, add and commit: Create Your First Git Repository”

Leave a Comment