Lesson 1 of 60 – Introduction to Git
2%

Introduction to Git

Git is a distributed version control system used to track changes in files and source code. It helps developers manage different versions of a project and work together efficiently.

Note: Git is a version control system, while GitHub is a platform that provides online hosting and collaboration features for Git repositories.

1. What is Git?

Git is a tool that records changes made to files in a project. It allows developers to save different versions of their work.

For example, if you are developing a website, Git can keep track of changes made to HTML, CSS, JavaScript and other files.

git --version

2. Why Do We Need Git?

Without version control, it can become difficult to know what changed in a project and when the change was made.

Git helps you:

  • Track changes
  • Save versions of a project
  • Restore previous versions
  • Work with other developers
  • Manage different features

3. Git is a Version Control System

Git is a Version Control System (VCS). A VCS records changes to files over time.

This allows developers to see the history of a project and return to an earlier version when required.

4. Git Tracks Changes

Git keeps a history of changes made to tracked files.

For example, suppose you initially create:

<h1>My Website</h1>

Later, you change it to:

<h1>My Personal Website</h1>

Git can help you keep track of this change.

5. Git Stores Project History

Git maintains a history of committed changes. Each commit represents a saved point in the project.

You can inspect this history using:

git log

6. What is a Repository?

A repository, commonly called a repo, is a location where Git stores information about a project and its version history.

A repository can contain source code, configuration files, documentation and other project files.

7. Local Repository

A local repository exists on your own computer. You can create one using:

git init

After running this command, Git creates a hidden .git directory.

8. The .git Directory

The .git directory contains important information used by Git to manage the repository.

You should normally avoid manually changing files inside this directory.

9. Working Directory

The working directory is the area where you create and edit project files.

For example:

my-project/
    index.html
    style.css
    script.js

10. Git Staging Area

The staging area is used to select changes that will be included in the next commit.

You can add a file to the staging area using:

git add index.html

To add all changed files:

git add .

11. What is a Commit?

A commit is a saved snapshot of the staged changes in a Git repository.

Example:

git commit -m "Add homepage"

The message describes what was included in the commit.

12. Git Workflow

A basic Git workflow is:

  1. Create or modify files
  2. Check the changes
  3. Add changes to the staging area
  4. Commit the changes
git status
git add .
git commit -m "Save changes"

13. Checking Git Status

The git status command shows the current state of your working directory and staging area.

git status

It can show modified files, untracked files and staged changes.

14. Git Commit History

The git log command displays the commit history.

git log

The history can contain commit IDs, authors, dates and commit messages.

15. Git is Distributed

Git is a distributed version control system. A complete repository can exist on each developer's computer.

This makes it possible to work on a project locally without requiring a constant connection to an online server.

16. Git Works Offline

Many Git operations can be performed without an internet connection.

For example, you can create commits, view history and create branches locally.

git add .
git commit -m "Local changes"

17. Git and Source Code

Git is widely used for software development projects. It can track source code written in languages such as:

  • HTML
  • CSS
  • JavaScript
  • PHP
  • Python
  • Java
  • C
  • C++

18. Git and Team Development

Git allows multiple developers to work on the same project. Developers can create branches, make changes and merge their work.

This makes Git useful for both individual and team projects.

19. Git Branches

A branch provides an independent line of development. It can be used to work on a feature without directly changing the main branch.

git branch feature-login

20. Git and GitHub

Git and GitHub are related but they are not the same thing.

Git is version control software. GitHub is an online platform that hosts Git repositories and provides collaboration features.

21. Git Remote Repository

A remote repository is a Git repository stored on another computer or online service.

A remote can be viewed using:

git remote -v

22. Git Push

The git push command sends local commits to a remote repository.

git push origin main

Here, origin is commonly used as the name of the remote repository.

23. Git Pull

The git pull command gets changes from a remote repository and integrates them into the current branch.

git pull origin main

24. Git Clone

The git clone command creates a local copy of an existing remote repository.

git clone https://example.com/project.git

After cloning, you can work with the repository on your computer.

25. Git Configuration

Git allows you to configure information such as your name and email.

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

This information is associated with your commits.

26. Git is Open Source

Git is open-source software. Its source code is publicly available, and developers can use Git without purchasing a proprietary Git license.

27. Common Git Commands

Some commonly used Git commands are:

git init
git status
git add .
git commit
git log
git branch
git switch
git merge
git pull
git push
git clone

28. Simple Git Example

A simple project workflow can look like this:

mkdir my-project
cd my-project

git init

git add .
git commit -m "Initial commit"

This creates a Git repository and records the first commit.

29. Advantages of Git

  • Tracks project changes
  • Maintains project history
  • Supports branches
  • Supports collaboration
  • Works offline
  • Helps recover previous versions
  • Works with many programming languages

30. Git Learning Roadmap

To learn Git effectively, start with basic commands and then move towards branches, merging and remote repositories.

  1. Learn Git basics
  2. Learn repositories
  3. Learn staging and commits
  4. Learn branches
  5. Learn merging
  6. Learn remote repositories
  7. Learn GitHub
  8. Practice with real projects

In the upcoming lessons, we will learn Git commands step by step and then work with GitHub.

📌 Key Points

  • Git is a distributed version control system.
  • Git tracks changes made to project files.
  • A Git repository stores project history.
  • git init creates a new Git repository.
  • git add adds changes to the staging area.
  • git commit saves staged changes.
  • git status shows the current repository state.
  • git log shows commit history.
  • Branches allow separate lines of development.
  • GitHub is an online platform for hosting and collaborating on Git repositories.

🧠 Quick Quiz

Question: What is Git?