๐ 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
-
Working Directory
The local directory where you're actively working. -
Staging Area (Index)
Temporary area to prepare changes before committing. -
.git Directory (Repository)
Internal database storing all history and config for the repo.
IV. Common Git Commands
A. Setup
B. Repository Management
C. Stage and Commit
D. Branching
E. Merging and Rebasing
F. Synchronizing
V. Git Branching Model
-
Main/Master – Main production branch.
-
Feature Branches – For developing new features.
-
Develop Branch – Integration branch for features (optional).
-
Release Branch – Used to stabilize a release.
-
Hotfix Branch – Quick fixes to production.
VI. Undo & Reset
Command | Description |
---|---|
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 --hard | Reset working dir and index (dangerous) |
VII. Tags
Used to mark specific points in history as important (e.g., releases).
VIII. Git Log and Diff
IX. Git Ignore
Use .gitignore
to prevent files from being tracked.
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
-
Use meaningful commit messages.
-
Make small, frequent commits.
-
Use branches for features/fixes.
-
Keep your main branch clean (always deployable).
-
Use Pull Requests/Merge Requests with peer review.
-
Never rebase/push force to shared branches unless coordinated.
Comments
Post a Comment