Master Git in 5 Minutes: Install and Make Your First Commit
This guide walks beginners through installing Git, configuring user identity, initializing a repository, adding files, and completing the first commit, while also explaining core concepts, common pitfalls, and the minimal workflow in a concise five‑minute tutorial.
Install Git
Verify installation with git --version. On Windows download from https://git-scm.com/ and follow the installer. On macOS run the same command; the system will prompt installation if missing.
Configure Identity
Set the global user name and email that will appear in commit records:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"Create a Repository
Create a project directory, enter it, and initialize an empty Git repository:
mkdir git-demo
cd git-demo
git initThe command prints Initialized empty Git repository, indicating the folder is now under version control.
Add a File
Create a file, for example hello.txt, with any content:
echo "Hello Git" > hello.txtStage the File
Prepare the file for commit: git add hello.txt Git tracks three states:
Working directory : files you are editing.
Staging area : files ready to be committed.
Repository : committed versions.
Make the First Commit
Commit the staged file with a message describing the change: git commit -m "First commit" Successful output includes 1 file changed, confirming the commit.
Minimal Git Workflow
Typical daily commands:
git add .
git commit -m "Your message"Workflow diagram:
modify file
↓
git add
↓
git commitView Commit History
Show the log of commits, including author, date, and message:
git logCommon Beginner Pitfalls
1. Commit without staging
Running git commit without a prior git add yields nothing to commit because no changes are staged.
2. Non‑ASCII paths
Use English‑only directory names (e.g., D:/project/git-demo) to avoid path‑related issues.
3. Not knowing what changed
Use git status to list modified, staged, and untracked files.
Summary of Completed Steps
Installed Git.
Configured user name and email.
Initialized a repository.
Added a file.
Made the first commit.
These actions establish the core Git workflow and enable reliable version tracking, safe experimentation, and collaborative development.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Code of Duty
"Code of Duty" — Every line of code has its own mission. We avoid shortcuts and quick fixes, focusing on authentic coding reflections and the joys and challenges of technical growth. The journey of learning matters more than any destination. Join us as we humbly forge ahead in the world of code.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
