๐Ÿ“˜ Git Summary Guide

 ๐Ÿ“˜ Git Summary Guide

I. What is Git?

Git is a distributed version control system used to track changes in source code. It enables multiple developers to collaborate, manage versions, and maintain a history of code changes.


II. Core Concepts

Concept

Description

Repository    

A directory that contains your project and Git metadata.

Commit

A snapshot of changes with a message.

Branch

A movable pointer to a commit; enables isolated development.

Merge

Combines changes from one branch into another.

Clone

Creates a local copy of a remote repository.

Pull

Fetches and merges changes from remote to local.

Push

Sends local commits to the remote repository.


III. Git Architecture

  1. Working Directory
    The local directory where you're actively working.

  2. Staging Area (Index)
    Temporary area to prepare changes before committing.

  3. .git Directory (Repository)
    Internal database storing all history and config for the repo.


IV. Common Git Commands

A. Setup

bash

git config --global user.name "Your Name" git config --global user.email "you@example.com"

B. Repository Management

bash

git init # Initialize a new repo git clone <url> # Clone a repo git remote add origin <url> # Add a remote

C. Stage and Commit

bash

git add <file> # Stage file(s) git add . # Stage all files git commit -m "Message" # Commit staged changes

D. Branching

bash

git branch # List branches git branch <name> # Create branch git checkout <name> # Switch branch git switch <name> # (Newer alternative)

E. Merging and Rebasing

bash

git merge <branch> # Merge changes git rebase <branch> # Reapply commits on top of another base

F. Synchronizing

bash

git fetch # Fetch from remote (no merge) git pull # Fetch + merge git push # Push to remote

V. Git Branching Model

  1. Main/Master – Main production branch.

  2. Feature Branches – For developing new features.

  3. Develop Branch – Integration branch for features (optional).

  4. Release Branch – Used to stabilize a release.

  5. Hotfix Branch – Quick fixes to production.


VI. Undo & Reset

CommandDescription
git checkout -- <file>Discard changes in a file
git reset HEAD <file>Unstage a file
git revert <commit>Create a new commit that undoes a previous one
git reset --hardReset working dir and index (dangerous)

VII. Tags

Used to mark specific points in history as important (e.g., releases).

bash

git tag v1.0.0 git push origin v1.0.0

VIII. Git Log and Diff

bash

git log # View commit history git log --oneline --graph # Compact history git diff # Show file changes git status # See file state

IX. Git Ignore

Use .gitignore to prevent files from being tracked.

bash

*.log node_modules/ .env

X. Git in CI/CD & DevOps

  • Git repositories serve as the source of truth for automation (e.g., Jenkins, GitLab CI).

  • GitOps is the practice of using Git as the single source of truth for infrastructure and deployments.


XI. Git Best Practices

  1. Use meaningful commit messages.

  2. Make small, frequent commits.

  3. Use branches for features/fixes.

  4. Keep your main branch clean (always deployable).

  5. Use Pull Requests/Merge Requests with peer review.

  6. Never rebase/push force to shared branches unless coordinated.



Comments

Popular posts from this blog

SAVE TAX ๐Ÿ’ต

LIFE A JOURNEY

๐ŸฆŸ The Truth About Mosquitoes: More Than Just an Itchy Bite