Your first repository and commit
25 min · Beginner
Need help? Ask a tutor on WhatsApp (opens in a new tab)Showing steps for Windows. They are marked “On Windows” below.
A repository is a project folder that Git tracks. A change goes from the folder you edit, through the staging area, into a commit: git add picks the change and git commit saves it.
Make a repository: git init
Repository (repo) is the Git word for a project folder that Git tracks. Git stores its full history, every commit, in a hidden .git folder inside it.
Git does not watch any folder until you ask. git init turns one project folder into a repository. You run it once per project, inside that project's folder.
On Windows
Make the folder and go into it: mkdir marks-report, then cd marks-report (cd moves into a folder, mkdir makes one). Then run git init; ls -Force also lists hidden items.
PS C:\Users\Priya\marks-report> git initPS C:\Users\Priya\marks-report> ls -ForceOutputInitialized empty Git repository in C:/Users/Priya/marks-report/.git/ Directory: C:\Users\Priya\marks-report Mode LastWriteTime Length Name ---- ------------- ------ ---- d--h-- 19-10-2026 10:02 .git
d--h--, d means folder and h means hidden. File Explorer shows it after View → Show → Hidden items.Run git init inside one project folder only, never in your home folder or on the Desktop: Git would track every file under it. Never edit or delete .git: it is the history.
Three areas: working folder, staging area, repository
Working directory (or working folder) is the project folder you see and edit: the real files on your disk, as File Explorer, Finder or your IDE shows them.
A change passes three areas before Git keeps it. Follow marks.txt: Priya saves it in the working folder, git add copies it to the staging area, and git commit saves it in the repository.
Example 1 · The file to track
Runs in: Your terminal
cat marks.txtMaths: 78 Physics: 85 Chemistry: 69
What this code does
- Save these three lines as
marks.txtinsidemarks-report, with VS Code, Notepad, TextEdit or any text editor.cat marks.txtprints the file in PowerShell and in Terminal. - Git tracks any kind of file, so a plain text file is enough. Everything in this lesson works the same for a Java, a Python or any other project.
Pick changes: git status and git add
Staging area (also called the index) is the list of changes you have picked for the next commit. git add puts a change there, and git commit saves everything in it as one commit.
git status tells you what changed and what is staged; run it before and after every step. A new file starts untracked: Git sees it but has never saved it. In VS Code, Terminal → New Terminal opens a terminal already inside marks-report.
git statusOn branch main No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) marks.txt nothing added to commit but untracked files present (use "git add" to track)
Example 2 · Stage the file
Runs in: Your terminal
git add marks.txtgit statusOn branch main No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: marks.txt
What this code does
git add marks.txtprints nothing. The file moved from Untracked files to Changes to be committed: it is staged.git add .stages every change in this folder and its subfolders. Readgit statusbefore using it, so nothing unwanted goes in.
Save a snapshot: git commit
Commit is the Git word for a saved snapshot of the staged changes in the repository. Each commit has a unique id, the author, the date and a message that says what changed.
git commit -m "message" saves everything that is staged. Write the message so it completes the sentence "This commit will…", for example Add marks for three subjects.
git commit -m "Add marks for three subjects"git status[main (root-commit) b5bdd9f] Add marks for three subjects 1 file changed, 3 insertions(+) create mode 100644 marks.txt On branch main nothing to commit, working tree clean
In the first line, main is the branch, root-commit means the very first commit and b5bdd9f is the commit's short id (yours will differ). nothing to commit, working tree clean means all three areas match.
no changes added to commit→ nothing is staged; rungit addfirst, then commit again.Author identity unknown→ setuser.nameanduser.email, as in Why version control? (opens in a new tab). Your staged changes are still waiting.
Change, add, commit again
Priya adds a Pass mark: 35 line to marks.txt and creates README.md. git status -s (short) shows two columns: the left one is the staging area, the right one is the working folder.
git status -sM marks.txt ?? README.md
Example 3 · Stage both changes and commit
Runs in: Your terminal
PS C:\Users\Priya\marks-report> git add .PS C:\Users\Priya\marks-report> git status -sPS C:\Users\Priya\marks-report> git commit -m "Add pass mark and README"OutputM marks.txt A README.md [main 49faf47] Add pass mark and README 2 files changed, 4 insertions(+) create mode 100644 README.md
What this code does
git add .staged both changes, so their letters moved to the left column:M(modified) andA(added, a new file).- One commit now holds both files, with the id
49faf47. - If a file has Unix line endings, Windows Git also prints
warning: ... LF will be replaced by CRLF the next time Git touches it. It is only about line endings; ignore it.
Short status at a glance: ?? untracked, M modified but not staged, M modified and staged, A new file staged, MM staged and then changed again. Commit small, finished steps, each with its own message.
Next step
Check your understanding
10 quick questions