Adding and Committing
A Git repository without any saved versions is like a time machine that hasn’t recorded any stops. We need to add and commit our work to take snapshots.
Creating a Sample File
Let’s create a simple text file inside your repository:
echo "Hello, Git!" > hello.txtNow run git status. You’ll see Untracked files: hello.txt. Git notices the file but isn’t tracking it yet.The Two‑Step Process: Add + Commit
1. Add the file to the staging area
The staging area is like a waiting room. You prepare changes you want to include in the next snapshot.
git add hello.txtNow git status shows Changes to be committed: new file: hello.txt.2. Commit the changes
Committing creates a permanent snapshot with a message describing what you did.
git commit -m "Add hello.txt with greeting"The -m flag lets you write a commit message directly. Always write meaningful messages – it’s like a caption for your snapshot.Understanding the Staging Area
Why separate add and commit? Because sometimes you work on multiple files but want to commit them in separate logical groups. The staging area lets you pick and choose what goes into each commit.
You can add all changed files at once with:
git add .View Your First Commit
After committing, run
git log to see the history:git logYou’ll see your commit with a unique hash, author, date, and message.Two Minute Drill
git add filenamestages changes – puts them in the waiting area.git commit -m "message"creates a permanent snapshot.- Always write clear commit messages.
- Use
git statusto see what is staged and what is not. - Use
git logto view commit history.
Need more clarification?
Drop us an email at career@quipoinfotech.com
