0
0
Gitdevops~5 mins

What is Git - CLI Guide

Choose your learning style9 modes available
Introduction
Git helps you save and track changes in your files. It solves the problem of losing work or mixing up different versions when you work on projects.
When you want to save different versions of your project safely.
When you work with friends on the same project and want to avoid conflicts.
When you want to see what changes were made and who made them.
When you want to try new ideas without breaking your main work.
When you want to keep a backup of your project history.
Commands
This command starts a new Git project in your current folder. It creates a hidden folder where Git keeps track of changes.
Terminal
git init
Expected OutputExpected
Initialized empty Git repository in /your/path/.git/
This command shows the current state of your project files and what changes are ready to be saved.
Terminal
git status
Expected OutputExpected
On branch main No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) README.md nothing added to commit but untracked files present (use "git add" to track)
This command tells Git to watch the file README.md and include it in the next save.
Terminal
git add README.md
Expected OutputExpected
No output (command runs silently)
This command saves the changes you marked with git add. The message explains what you changed.
Terminal
git commit -m "Add README file"
Expected OutputExpected
[main (root-commit) abcdef1] Add README file 1 file changed, 1 insertion(+) create mode 100644 README.md
-m - Adds a message describing the commit
This command shows a short list of all saved changes with their messages.
Terminal
git log --oneline
Expected OutputExpected
abcdef1 Add README file
--oneline - Shows each commit in one short line
Key Concept

If you remember nothing else from this pattern, remember: Git saves your work history so you can track, share, and recover your project easily.

Common Mistakes
Not running git add before git commit
Git does not know which files to save, so your changes are not recorded.
Always run git add <filename> to mark files before committing.
Writing unclear commit messages
It becomes hard to understand what changes were made later.
Use clear, short messages that explain the purpose of the change.
Summary
git init creates a new Git project to start tracking files.
git add marks files to be saved in the next commit.
git commit saves the marked changes with a message.
git status shows what files are changed or ready to save.
git log shows the history of saved changes.