0% found this document useful (0 votes)
3 views15 pages

GIT Introduction With Example

Git is a distributed version control system that allows developers to track changes, collaborate on projects, and manage code history effectively. It simplifies version management by enabling easy rollbacks and simultaneous work by multiple developers, distinguishing itself from GitHub, which is a cloud platform for hosting Git repositories. Key concepts include repositories, commits, branches, and a structured workflow that enhances team collaboration and project management.

Uploaded by

ssindhiya1111
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views15 pages

GIT Introduction With Example

Git is a distributed version control system that allows developers to track changes, collaborate on projects, and manage code history effectively. It simplifies version management by enabling easy rollbacks and simultaneous work by multiple developers, distinguishing itself from GitHub, which is a cloud platform for hosting Git repositories. Key concepts include repositories, commits, branches, and a structured workflow that enhances team collaboration and project management.

Uploaded by

ssindhiya1111
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Git – A Detailed Introduction (Simple Explanation with

Examples and Workflow)


Git is the world's most popular Version Control System (VCS). It helps developers track
changes, collaborate on projects, and safely manage code over time.

Think of Git as a time machine for your code. If you make a mistake, you can go back to
a previous version.

1. What is Git?
Git is a distributed version control system used to:
Track changes in files
Collaborate with other developers
Maintain version history
Restore previous versions
Manage multiple features simultaneously

Git was created by Linus Torvalds (the creator of Linux) in 2005.

2. Real-Life Example
Imagine you are writing a book.

Normally, you might save files like:

[Link]
Book_Final.docx
Book_Final2.docx
Book_Final_Final.docx
Book_Final_Really_Final.docx

This quickly becomes confusing.

With Git, you simply save meaningful versions:

Version 1
Version 2
Version 3
Version 4

Git remembers who changed what, when, and why.


3. Why Do We Need Git?
Without Git:
Files get overwritten
No history of changes
Difficult collaboration
Hard to recover deleted code

With Git:
Every change is tracked
Easy rollback
Team collaboration
Multiple developers can work simultaneously

4. What is Version Control?


Version control means keeping a history of changes made to files.

Example:

Version 1

Version 2

Version 3

Version 4

If Version 4 has a bug:

Rollback

Version 3

5. Git vs GitHub
Many beginners confuse these.

Git GitHub

Software installed on your computer Cloud platform

Tracks versions Stores Git repositories online

Works offline Requires internet for synchronization

Free and open source Provides collaboration, pull requests, issues

Example:

Laptop
|
Git
|
GitHub

6. What is a Repository (Repo)?


A repository is a project managed by Git.

Example:

ShoppingApp/

[Link]

[Link]

[Link]

[Link]

Git tracks every file inside the repository.

7. Installing Git
After installation, Git is available from the terminal.

Verify installation:
Bash

git --version

Example output:

git version 2.48.1

8. Initialize a Git Repository


Create a project:

Bash

mkdir MyProject
cd MyProject

Initialize Git:

Bash

git init

Result:

MyProject/

.git/

(project files)

The hidden .git folder stores all version history.

9. Git Workflow (Pathway)


Git follows a simple workflow:

Working Directory

Staging Area

Local Repository

Remote Repository (GitHub)

10. Detailed Git Data Flow


Suppose you edit a file.

Create File

Modify File

git add

Staging Area

git commit

Local Repository

git push

GitHub

11. Understanding the Workflow


Step 1 – Working Directory
You create or edit files.

[Link]

Status:

Modified

Step 2 – Staging Area


Stage changes:

Bash

git add [Link]

Status:

Ready to Commit

Step 3 – Local Repository


Save the changes:

Bash

git commit -m "Added login page"

Git creates a permanent snapshot.

Step 4 – Remote Repository


Upload changes:

Bash

git push

Now everyone can access the latest version.


12. Visual Workflow

Developer

Working Directory

git add

Staging Area

git commit

Local Repository

git push

GitHub

13. Checking Repository Status


Command:

Bash

git status

Example output:

Modified:
[Link]
This tells you which files have changed.

14. Viewing Change History


Command:

Bash

git log

Example:

Commit A

Commit B

Commit C

Commit D

Each commit has a unique ID.

15. What is a Commit?


A commit is a snapshot of your project at a specific point in time.

Example:

Commit 1

Login Page

Commit 2

Registration Page
Commit 3

Password Reset

Each commit includes:


Commit ID
Author
Date
Message

16. What is a Branch?


A branch lets you work on a feature without affecting the main code.

Example:

Main Branch

+----------------+

| |

Feature A Feature B

Developers can work independently.

17. Why Use Branches?


Imagine an e-commerce website.

Main branch:

Website is live

Developer creates:

feature/payment

feature/search
Each feature is developed separately and merged later.

18. Merging Branches


After completing a feature:

Main

+------Feature Branch

Development Complete

Merge

Main Updated

Command:

Bash

git merge feature/payment

19. What is GitHub?


GitHub hosts Git repositories online.

Benefits:

Backup
Team collaboration
Pull Requests
Code Reviews
Issue Tracking
CI/CD Integration
20. Clone a Repository
Download an existing project:

Bash

git clone [Link]

Result:

GitHub

Internet

Your Laptop

21. Push and Pull


Push
Uploads local commits to GitHub.

Bash

git push

Laptop

GitHub

Pull
Downloads the latest changes.

Bash

git pull
GitHub

Laptop

22. Real-Life Team Workflow


Suppose three developers work on the same project.

Developer A

Developer B

Developer C

GitHub

Main Project

Each developer:
1. Creates a branch
2. Makes changes
3. Commits locally
4. Pushes to GitHub
5. Creates a Pull Request
6. Gets the code reviewed
7. Merges into the main branch

23. Common Git Commands


Command Purpose

git init Initialize a repository


Command Purpose

git clone Copy a remote repository

git status Show current status

git add Stage changes

git commit -m "message" Save a snapshot

git log View commit history

git branch List branches

git checkout branch-name Switch branches

git switch branch-name Modern way to switch branches

git merge branch-name Merge a branch

git pull Download latest changes

git push Upload commits

git diff Show file differences

24. Complete End-to-End Example


You want to add a login page.

Create [Link]

Edit [Link]

git status

git add [Link]


git commit -m "Added login page"

git push

GitHub Repository Updated

Team pulls the latest code

Application includes the new login page

25. Key Git Concepts to Learn Next


Once you're comfortable with the basics, study these topics in order:
1. Git Architecture (Working Directory, Staging Area, Repository)
2. Git Repository Initialization
3. Tracking and Untracking Files
4. Commits and Commit History
5. Branching and Branch Management
6. Merging and Merge Conflicts
7. Remote Repositories (GitHub, GitLab, Azure Repos)
8. Cloning, Pushing, and Pulling
9. Pull Requests (PRs) and Code Reviews
10. .gitignore
11. Tags and Releases
12. Rebasing ( git rebase )
13. Cherry-picking ( git cherry-pick )
14. Stashing ( git stash )
15. Undoing Changes ( git restore , git reset , git revert )
16. Git Hooks
17. Git Workflows (Feature Branch, Git Flow, Trunk-Based Development)
18. CI/CD Integration with Git (GitHub Actions, Azure DevOps, Jenkins)

Mastering these Git fundamentals will make it much easier to work with collaborative
software projects, DevOps pipelines, cloud deployments, and enterprise development
environments.

You might also like