What Creating a Repository Does
A repository is a folder whose history Git records. You turn an ordinary
folder into one with git init. The command creates a hidden folder called
.git inside it, where Git keeps the commits and the staging area from the
previous lesson. Nothing else changes: your files stay as they are, and Git
tracks none of them until you add them.
Never edit or delete files inside .git yourself. Git manages its contents,
and deleting the folder deletes the whole history.
Git finds the repository by looking for .git in the current folder, then in
each parent folder above it. That is why Git commands work from any subfolder
of a project, and why they fail in a folder that has no repository above it.
This course creates repositories with:
git init -b main
-b main names the first branch main. Your init.defaultBranch setting from
the configuration lesson already does this, but writing it in the command
makes the result the same on any computer. Git 2.28 added -b.
Exercise: Create a Repository
You will create a repository, record its first commit and confirm the result.
Everything happens in ~/git-practice/first-repository, which the last step
removes.
Starting state: Git configured as in the configuration lesson, and the
~/git-practice folder from the setup lesson.
-
Create the exercise folder, enter it and ask Git about it before creating a repository:
mkdir -p ~/git-practice/first-repository cd ~/git-practice/first-repository git statusIllustrative output:
fatal: not a git repository (or any of the parent directories): .gitGit found no
.gitfolder here or in any folder above it, so there is no repository to report on. The exact wording can vary between systems. -
Create the repository and look at the folder, including hidden items:
git init -b main ls -als -alists everything, including names that start with a dot, which plainlshides. Illustrative output, with your own path:Initialized empty Git repository in /home/asha/git-practice/first-repository/.git/ . .. .git.means this folder and..its parent..gitis the new repository. -
Ask Git again:
git statusIllustrative output:
On branch main No commits yet nothing to commit (create/copy files and use "git add" to track)Git now recognises the repository. It is on the
mainbranch, has no commits, and has nothing staged. -
Create a file and see how Git describes it:
printf '# Practice project\n\nNotes for learning Git.\n' > README.md git statusThe file appears under
Untracked files: it exists in the working tree, but Git has not been asked to track it. -
Stage the file, check, then record the first commit:
git add README.md git status git commit -m "Add project README"After
git add, the status listsnew file: README.mdunderChanges to be committed.-msupplies the commit message on the command line, so no editor opens. Illustrative output from the commit:[main (root-commit) f95062a] Add project README 1 file changed, 3 insertions(+) create mode 100644 README.mdThe first line names the branch, marks this as the root commit (the first one, with no parent), shows the shortened commit ID, which will differ on your computer, and repeats the message. The next line counts the change: one file, three lines added.
create mode 100644records that a new ordinary file was added. -
Confirm the result:
git log git statusIllustrative output:
commit f95062a3d2df10fb27f6b5dd477036b69ce89c23 Author: Asha Rao <asha@example.com> Date: Fri Oct 9 00:23:01 2026 +0530 Add project README On branch main nothing to commit, working tree cleangit logshows the full commit ID, the author from your configuration, the date and the message.git statusreports that the working tree, staging area and last commit all agree. -
Clean up:
cd ~/git-practice ls rm -rf first-repository ls
Success: git log shows exactly one commit, with your name, your email and
the message Add project README, and git status reports
nothing to commit, working tree clean on branch main.
If something differs:
| What you see | Likely cause | Next step |
|---|---|---|
| Step 1 shows a branch instead of an error | A folder above the exercise is already a repository | Run git rev-parse --show-toplevel to see which folder; practise somewhere outside it |
On branch master | The repository was created without -b main and without the setting | Remove the folder and start the exercise again |
Author identity unknown | Name or email not configured | Set them as in the configuration lesson, then commit again |
nothing added to commit but untracked files present | git commit ran before git add | Run git add README.md, then commit |
pathspec 'READNE.md' did not match any files | The file name was mistyped, or the file is in another folder | Check with ls and pwd, then add the correct name |
not a git repository after step 2 | You are in a different folder | Run pwd, then cd ~/git-practice/first-repository |
Independent task: without copying the steps above, create a repository in
~/git-practice/my-notes, add a file of your own with a sentence in it, and
record it as the first commit with a message describing the file. Show that
there is exactly one commit and that the working tree is clean, then remove the
folder.
Check Your Understanding
You open a new terminal, which starts in your home folder, and run
git status. It prints not a git repository, yet a minute ago git status
worked in ~/git-practice/first-repository. Explain why, and say what
determines which repository a Git command works on.
Answer and Reasoning
Independent task
One correct sequence:
mkdir -p ~/git-practice/my-notes
cd ~/git-practice/my-notes
git init -b main
printf 'Ideas for my first project.\n' > ideas.txt
git add ideas.txt
git commit -m "Add project ideas"
git log --oneline
git status
cd ~/git-practice
rm -rf my-notes
Your file name, text and message can differ. The checks are what matter: one
line in git log --oneline and nothing to commit, working tree clean in
git status, with the folder removed only after you moved out of it.
Understanding check
Git works on the repository containing your current folder. It looks for
.git in the current folder, then in each folder above it. The new terminal
starts in your home folder, which has no .git and is not inside a repository,
so there is nothing to report. In ~/git-practice/first-repository, Git found
the .git folder created by git init. Move into the project folder, or a
subfolder of it, before running Git commands.