What is Git and how git work

Git is a distributed version control system (DVCS) that helps developers manage changes to source code during software development. It allows multiple developers to work on the same project simultaneously, tracks every change made to the code, and helps revert to previous states when necessary.

Aug 17, 2025 - 09:31
Aug 17, 2025 - 09:39
 0  2
What is Git and how git work

What is Git?

Git is:

  • Free and open-source

  • Created by Linus Torvalds in 2005 (the creator of Linux)

  • Designed for speed, efficiency, data integrity, and support for distributed, non-linear workflows


Why Use Git?

  • Version history: Tracks changes over time

  • Collaboration: Multiple developers can work on the same project

  • Branching: Create isolated environments for features or bug fixes

  • Backup: Every user has a full copy of the repository


Key Concepts in Git

1. Repository (repo)

  • A directory where your project lives.

  • Contains all files, history, branches, tags, etc.

  • Can be local (on your computer) or remote (like GitHub, GitLab, Bitbucket).

2. Working Directory

  • The current directory you are working in.

  • Contains actual files from the latest commit.

3. Staging Area (Index)

  • A file where you list what will go into your next commit.

  • Allows selective commits.

4. Commit

  • A snapshot of your changes.

  • Contains a unique hash, author, timestamp, and commit message.

5. Branch

  • A lightweight movable pointer to a commit.

  • Default branch: main or master

  • Use branches for new features, fixes, or experiments.

6. Merge

  • Combines two branches into one.

  • Preserves history and changes from both.

7. Clone

  • Make a copy of an existing repository.

8. Pull

  • Fetch and merge changes from the remote repo to your local one.

9. Push

  • Send your local commits to the remote repo.

10. Remote

  • A version of your repository hosted on the internet or network.


Common Git Commands

Initialization

git init # Create a new Git repo git clone
# Clone an existing repo

Working with Changes

git status # Check file status git add
# Stage a file git add .
# Stage all files git commit -m "message"
# Commit changes git diff
# View unstaged changes git log # View commit history

Branching & Merging

git branch # List branches git branch
# Create a branch git checkout
# Switch to a branch git merge # Merge branch into current

Remote Repositories

git remote add origin # Add remote repo git push origin
# Push branch to remote git pull origin
# Pull branch from remote git fetch # Fetch changes from remote

Advanced Git Features

Tags

  • Mark specific points (usually releases)

git tag v1.0 git push origin v1.0

Rebase

  • Linearize history

git rebase

Stash

  • Temporarily save changes

git stash git stash apply

Cherry-pick

  • Apply a specific commit from another branch

git cherry-pick

Reset vs Revert

  • reset: Move HEAD to a different commit (can lose data)

  • revert: Create a new commit that undoes changes


 Git Workflow Example

  1. git clone https://github.com/user/repo.git

  2. cd repo

  3. Make changes

  4. git add .

  5. git commit -m "Add new feature"

  6. git push origin main


Popular Git Workflows

  • Feature Branch Workflow

  • Gitflow Workflow

  • Forking Workflow

  • Trunk-based Development

Each has different strategies for branching and merging, depending on team needs.


 Git Hosting Services

  • GitHub – most popular

  • GitLab

  • Bitbucket

  • Azure Repos

These platforms add features like:

  • Pull requests (code reviews)

  • Issue tracking

  • CI/CD pipelines


 Git Configuration

git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --list # Show settings

 Tools That Use Git

  • Git GUI Clients: GitKraken, Sourcetree, GitHub Desktop

  • IDEs with Git Integration: VSCode, IntelliJ, Eclipse

  • CI/CD Tools: Jenkins, GitHub Actions, GitLab CI

Git is a free and open-source distributed version control system used to track changes in source code during software development. It allows multiple developers to work on a project simultaneously, manage different versions of code, and collaborate efficiently. Git makes it easy to revert to previous code states, manage branches, and synchronize code with remote repositories like GitHub or GitLab.


What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Angry Angry 0
Sad Sad 0
Wow Wow 0