Open In App

Git Introduction

Last Updated : 26 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Git is a version control system that helps you keep track of all the changes made to your code. It is like a time machine for your code. Whenever you make changes to a file, Git can store those changes, so you can go back to previous versions if something goes wrong.

It also allows multiple developers to work on the same project at the same time without interfering with each other's work. It helps prevent confusion and conflicts when people make changes to the same files.

git

Use of Git

Git brings numerous advantages to developers:

  1. Collaboration: Git enables multiple developers to work on the same project simultaneously. Changes can be merged seamlessly, and conflicts can be resolved easily.
  2. History Tracking: Every change is recorded, allowing you to revert to previous versions of your code if something goes wrong.
  3. Branching and Merging: Git allows you to create branches for new features or experiments without affecting the main codebase. Once the feature is ready, it can be merged back into the main branch.
  4. Distributed Development: Each developer has a complete copy of the repository, including its history. This decentralization enhances collaboration and backup capabilities

Core Concepts of Git

Before using Git, it is important to understand some of its core concepts. These concepts will help you get started and make it easier to work with Git in real-world scenarios.

1. Repositories

A repository (or repo) is a storage space where your project files and their history are kept. There are two types of repositories in Git:

  • Local Repository: A copy of the project on your local machine.
  • Remote Repository: A version of the project hosted on a server, often on platforms like GitHub, GitLab, or Bitbucket.
Types-of-Repository

2. Commits

A commit is a snapshot of your project at a specific point in time. Each commit has a unique identifier (hash) and includes a message describing the changes made. Commits allow you to track and review the history of your project.

GitCommit1

To read more about Git Commit Click here

3. Branches

Branches allow developers to work on separate tasks without affecting the main codebase. Common branch types include:

  • Main (or Master) Branch: The stable version of the project, usually production-ready.
  • Feature Branch: Used for developing new features or bug fixes.
git_branch

4. Merging

Merging is the process of integrating changes from one branch into another. It allows you to combine the work done in different branches and resolve any conflicts that arise.

git_merging

5. Cloning

Cloning a repository means creating a local copy of a remote repository. This copy includes all files, branches, and commit history.

GitClone0

To Read more about Git Clone Click here

6. Pull and Push

  • Pull: Fetches updates from the remote repository and integrates them into your local repository.
  • Push: Sends your local changes to the remote repository, making them available to others.
commit

Read more:

GitHub and it's Importance

GitHub is a platform that hosts Git repositories online. It allows you to:

  • Store your code in the cloud.
  • Collaborate with others.
  • Track issues and review pull requests.

While Git is the tool that helps you track changes, GitHub is the website where you can host and share your Git repositories (or "repos" for short). GitHub provides a more visual way to work with Git, making it easier to understand what’s happening in your code.

To learn more about GitHub Click here

Getting Started with Git

If you are new to Git, the first thing you need to do is set it up, configure it, and start your first project. Here's a simple guide to help you get started with Git:

Step 1: Installing Git

Git can be installed on various operating systems. Follow the installation instructions provided for various OS:

How to Install Git on Windows - 4 Methods

We will walk you through each step of the installation process and provide helpful tips to get you started with Git on your Windows machine.

Method 1: Install Git using the Official Git for Windows Installer

The easiest and most recommended way to install Git on Windows is through the official Git for Windows installer. This method provides the most up-to-date version and ensures that Git runs smoothly on your system.

Step 1: Download the Installer

Go to the official Git website: https://git-scm.com/download/win.

gitwindows0

The download will start automatically for the latest version of Git for Windows. After the download is complete, run the .exe file.

Step 2: Select Editor & Adjust Path

Follow the prompts in the setup wizard. Most default settings will be fine for general use, but here are some key steps:

  • Firstly, the installer will ask which text editor to use for Git. You can choose from options like Vim, Notepad++, or Visual Studio Code.
  • Make sure you choose the option that adds Git to your system PATH (recommended for ease of use in the command line).
  • Select the default option (OpenSSL) to allow Git to communicate securely over HTTPS.
  • The default choice, “Checkout Windows-style, commit Unix-style line endings,” is ideal for most developers working in Windows environments.

Step 3: Complete the Installation

After configuring the setup, click "Install" and allow the installation to complete.

Once done, you can launch Git Bash (installed with Git) or use Git from the Command Prompt (cmd) by typing the following command.

git --version
verify2

Method 2: Install Git Using Chocolatey Package Manager

Chocolatey is a package manager for Windows that makes it easy to install software using simple commands. You can install Git using Chocolatey if you prefer using command-line tools to manage your software.

Step 1: Install Chocolatey (if not already installed)

Open PowerShell as Administrator.

powershell-as-admin

Run the following command to install Chocolatey:

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

Step 2: Install Git

After installing Chocolatey, use the following command to install Git:

choco install git
choco2

Chocolatey will download and install the latest version of Git on your system.

Step 3: Verify Installation

Open Command Prompt or PowerShell and type the following command to confirm the installation.

git --version
verify2

Method 3: Install Git Using Windows Subsystem for Linux (WSL)

Windows Subsystem for Linux (WSL) allows you to run a Linux distribution alongside your Windows environment. If you're using WSL, you can install Git as you would on a native Linux system.

Step 1: Install WSL

Open PowerShell as Administrator and run the following command to install WSL:

wsl --install
wsl91

Restart your PC when prompted.

Step 2: Install Git within WSL

Once WSL is set up, open the WSL terminal (Ubuntu or your preferred Linux distribution).

Use the following command to install Git:

sudo apt update
sudo apt install git
wslnew1

Step 3: Verify Installation

In your WSL terminal, type the following command to verify the installation.

git --version 

Method 4: Install Git via GitHub Desktop

GitHub Desktop provides a graphical interface for managing your Git repositories, which is great for beginners or those who prefer not to work with the command line. You can install Git through GitHub Desktop, which includes Git along with additional features for managing GitHub repositories.

Step 1: Download GitHub Desktop

Visit the GitHub Desktop website and download the installer for Windows.

winn3333

Step 2: Run the Installer

Open the installer and follow the on-screen instructions to complete the installation.

winnnn1-768

Step 3: Verify Git Installation

After installation, you can verify Git by opening the GitHub Desktop application, or you can open Git Bash or Command Prompt and type

git --version
verify2

Step 2: Create a GitHub Account

Next, you need to create a free account on GitHub by visiting github.com. After you sign up, you will be able to create repositories and share your code with others.

Step 3: Configure Git

Once Git is installed, you need to tell it who you are. Open your terminal and type the following commands:

git config --global user.name "Your Name"
git config --global user.email "[email protected]"

These commands set your username and email, which Git will use to track your commits (changes you make to your code).

Step 4: Create a Local Git Repository

To start using Git for a project, you need to create a repository (or "repo"). A repo is where Git stores your project and tracks changes. Open your terminal, navigate to the folder where you want to store your project, and run:

git init

This initializes a new Git repository in that folder.

Step 5: Add Files to Your Repo

Next, you can create or add files to your project. For example, create a new file called myfile.txt:

touch myfile.txt

Git won't track the new file until you tell it to. You can use the following command to tell Git to start tracking the file:

git add myfile.txt

This command stages the file, preparing it for the next commit.

Step 6: Commit Your Changes

A commit is like a snapshot of your project at a certain point of time. To commit your changes, use the command:

git commit -m "Added myfile.txt"

This saves your changes to the Git repository with a message describing what you changed.

Step 7: Create a Remote Repository on GitHub

Now, you can upload your local repository to GitHub. First, go to GitHub, click on the “+” button in the top-right corner, and select "New Repository". Follow the instructions to create a new repository.

Once the repository is created, GitHub will show you how to link it to your local project. For example:

git remote add origin https://github.com/yourusername/yourrepository
git push -u origin master

This uploads your project from your computer to GitHub.

Step 8: Create a Branch and Make Changes

Branches allow you to make changes to your project without affecting the main version. To create a new branch, use:

git checkout -b new-feature

This switches you to a new branch called new-feature. You can now make changes to your project without affecting the main branch (usually called master or main).

Step 9: Push your Changes to GitHub

Once you have made changes on your new branch, you can push those changes to GitHub.

Run:

git push origin new-feature

Step 10: Create a Pull Request (PR)

A pull request (PR) is a way to suggest changes to a project. It allows others to review your changes before merging them into the main branch. On GitHub, go to your repository, click on “Pull Requests,” and create a new PR.

Basic Git Commands

Git commands are important for navigating and controlling your project repository. These commands help you manage files, track changes, and collaborate with others.

CommandDescription
git statusShows the current status of the repository — staged, unstaged, and untracked files.
git add <file-name>Stages a specific file for commit. Use git add . to stage all changes.
git commit -m "message"Commits the staged changes with a descriptive commit message.
git branch <branch-name>Creates a new branch with the given name.
git checkout <branch-name>Switches to the specified branch.
git merge <branch-name>Merges changes from the given branch into the current branch.
git push origin <branch-name>Pushes the local branch changes to the remote repository.
git pull origin <branch-name>Fetches and merges changes from the remote repository into the local branch.
git logDisplays the commit history for the current branch.

Git Workflow

Git-Workflow

Git workflows define how developers should use Git in a structured and efficient manner.

1. Clone the Repository

git clone [email protected]:username/repository.git

2. Create and Switch to a New Branch

git checkout -b feature-branch

3. Make Changes and Stage Them

git add <file-name>

4. Commit the Changes

git commit -m "Add new feature"

5. Push the Changes

git push origin feature-branch

6. Create a Pull Request: After pushing your changes, create a pull request on GitHub to merge the feature branch into the main branch.

7. Update your Local Repository

git checkout main
git pull origin main

8. Delete Feature Branch:

git branch -d feature-branch
git push origin --delete feature-branch

Git is an essential tool for modern software development and plays a critical role in DevOps workflows. By understanding how to set up and use Git, work with branches, and manage code effectively, you can collaborate more efficiently with your team and ensure that your software development process is organized and streamlined. As a DevOps learner, mastering Git is a important step towards building a successful and scalable development workflow.


Next Article
Practice Tags :

Similar Reads