Skip to content

Latest commit

 

History

History
142 lines (106 loc) · 2.03 KB

File metadata and controls

142 lines (106 loc) · 2.03 KB

Git Commands Reference

Setup & Configuration

Configure Git

git --version

Shows installed Git version.

git --version

git config --global user.name

Sets your global Git username.

git config --global user.name "Sabir"

git config --global user.email

Sets your Git email address.

git config --global user.email "[email protected]"

git config --list

Displays current Git configuration.

git config --list

Create Your Git Project

Repository Initialization

Task 2

git init

Initializes a new Git repository in the current directory.

git init

Creates a hidden .git/ folder that stores repository metadata.


Create Git Commands Reference

Task 3

git status

Shows the state of working directory and staging area.

git status

git add

Stages a file for the next commit.

git add git-commands.md

Task 4

git add .

Stages all modified files.

git add .

git commit -m "message"

Creates a snapshot of staged changes.

git commit -m "Initial Git command reference"

Viewing Changes

git diff

Shows unstaged changes.

git diff

git diff --staged

Shows staged changes before commit.

git diff --staged

Task 5

git log

Shows commit history.

git log

git log --oneline

Compact commit history view.

git log --oneline

File Tracking

git rm

Removes file from repository.

git rm oldfile.txt

git mv

Renames or moves a file.

git mv old.txt new.txt

Good Practice Notes

  • Commit often, but meaningfully.
  • One logical change per commit.
  • Write descriptive commit messages.
  • Always check git status before committing.

Git Workflow Summary

Working Directory → Staging Area → Repository

  1. Modify files
  2. Stage changes (git add)
  3. Commit snapshot (git commit)
  4. View history (git log)