Git Foundations / Record Your Work

Create a repository

Lesson 5 of 33. Open to read. No account needed.

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.

  1. 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 status
    

    Illustrative output:

    fatal: not a git repository (or any of the parent directories): .git
    

    Git found no .git folder here or in any folder above it, so there is no repository to report on. The exact wording can vary between systems.

  2. Create the repository and look at the folder, including hidden items:

    git init -b main
    ls -a
    

    ls -a lists everything, including names that start with a dot, which plain ls hides. 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. .git is the new repository.

  3. Ask Git again:

    git status
    

    Illustrative 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 main branch, has no commits, and has nothing staged.

  4. Create a file and see how Git describes it:

    printf '# Practice project\n\nNotes for learning Git.\n' > README.md
    git status
    

    The file appears under Untracked files: it exists in the working tree, but Git has not been asked to track it.

  5. 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 lists new file: README.md under Changes to be committed. -m supplies 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.md
    

    The 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 100644 records that a new ordinary file was added.

  6. Confirm the result:

    git log
    git status
    

    Illustrative 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 clean
    

    git log shows the full commit ID, the author from your configuration, the date and the message. git status reports that the working tree, staging area and last commit all agree.

  7. 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 seeLikely causeNext step
Step 1 shows a branch instead of an errorA folder above the exercise is already a repositoryRun git rev-parse --show-toplevel to see which folder; practise somewhere outside it
On branch masterThe repository was created without -b main and without the settingRemove the folder and start the exercise again
Author identity unknownName or email not configuredSet them as in the configuration lesson, then commit again
nothing added to commit but untracked files presentgit commit ran before git addRun git add README.md, then commit
pathspec 'READNE.md' did not match any filesThe file name was mistyped, or the file is in another folderCheck with ls and pwd, then add the correct name
not a git repository after step 2You are in a different folderRun 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.

References

Study this course with an account

Course access adds revision notes, the Quick Reference, saved progress, bookmarks and your own notes.

INR 99 plus 18% GST. 90 days of online access. No auto-renewal.

See course access

This website is operated by VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED, operating as Vectametric.

Corporate Identity Number (CIN): U85499KA2026OPC229822. GSTIN: 29AAMCV8281D1ZS. Registered office: RS NO/38/2A/1 BASTAND, ROAD MAHANTESH NAGAR, Ramdurg, Ramdurg, Belgaum- 591123, Karnataka.

Queries and grievances: Prajval Honnungar, Grievance Officer and Data Protection Contact.

Telephone: +91 94800 09310. Support: support@vectametric.com. Grievances: support@vectametric.com.

Copyright 2026 VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED. All rights reserved.

Vectametric home · Roadmaps · Vecta IT Exams · Vecta Government Exams · Vecta Banking & Finance Exams · Vecta Entrance Exams · About us · Contact · Privacy Policy · Terms and Conditions · No-Refund Policy