0
0
Gitdevops~5 mins

Repository (committed history) in Git - Commands & Configuration

Choose your learning style9 modes available
Introduction
A repository stores all the files and their changes over time. Committed history lets you see what was changed, when, and by whom. This helps track progress and fix mistakes.
When you want to save a snapshot of your project to keep track of changes.
When you need to see who changed a file and why.
When you want to go back to an earlier version of your project.
When you want to share your project history with teammates.
When you want to review the sequence of changes before deploying.
Commands
This command creates a new Git repository in your current folder. It starts tracking changes.
Terminal
git init
Expected OutputExpected
Initialized empty Git repository in /home/user/my-project/.git/
This command stages all current files to be included in the next commit. It tells Git what changes to save.
Terminal
git add .
Expected OutputExpected
No output (command runs silently)
This command saves the staged changes as a new commit with a message describing the changes.
Terminal
git commit -m "Initial commit"
Expected OutputExpected
[master (root-commit) abc1234] Initial commit 3 files changed, 45 insertions(+) create mode 100644 file1.txt create mode 100644 file2.txt create mode 100644 file3.txt
-m - Adds a commit message inline without opening an editor
This command shows a short summary of the commit history, listing each commit on one line.
Terminal
git log --oneline
Expected OutputExpected
abc1234 Initial commit
--oneline - Shows each commit in a compact single line format
Key Concept

If you remember nothing else from this pattern, remember: commits save snapshots of your project so you can track and revisit changes anytime.

Common Mistakes
Not running 'git add' before 'git commit'
Git will not include any changes in the commit if they are not staged with 'git add'.
Always stage your changes with 'git add' before committing.
Using vague commit messages like 'update' or 'fix'
Vague messages make it hard to understand what changed and why when reviewing history.
Write clear, descriptive commit messages that explain the purpose of the change.
Summary
Initialize a Git repository with 'git init' to start tracking your project.
Stage changes using 'git add' to prepare them for saving.
Save changes as commits with 'git commit -m' including a clear message.
View your commit history with 'git log --oneline' to see past snapshots.