DevOps & Linux Administration

Git & GitHub Basics


Module VI: Git & GitHub Basics. This module introduces version control systems, Git fundamentals, GitHub workflows, repositories, commits, branches, and collaboration techniques used in modern software development and DevOps environments.


What is Version Control?

Version control is a system used to track changes made to files and source code over time. It allows developers to maintain project history, collaborate with teams, and restore previous versions whenever required.

Modern software development heavily relies on version control systems for teamwork and project management.

Version Control Workflow

Write Code
Save Changes
Track Versions
Collaborate with Team

What is Git?

Git is a distributed version control system developed by Linus Torvalds. It helps developers manage source code, track changes, and collaborate efficiently on projects.

Git stores snapshots of project files and maintains a complete history of changes made during development.

Fast

Git operations are highly optimized and efficient.

Distributed

Every developer has a complete copy of repository history.

Reliable

Git safely tracks and manages code changes.


What is GitHub?

GitHub is a cloud-based platform used to host Git repositories online. It enables developers to collaborate, share code, review contributions, and manage projects efficiently.

GitHub is widely used in open-source projects, software companies, and DevOps workflows.

GitHub Collaboration Flow

Developer Writes Code
Commit Changes
Push to GitHub Repository
Team Reviews & Collaborates

Repositories

A repository (repo) is a storage location for project files and Git history. It contains source code, documentation, configuration files, and commit history.

Repository TypeDescription
Local RepositoryStored on user's computer
Remote RepositoryHosted online on GitHub or cloud platforms

Basic Git Commands

Git provides various commands to initialize repositories, track changes, and synchronize code.

CommandPurpose
git initInitializes a Git repository
git statusShows repository status
git addAdds files to staging area
git commitSaves changes permanently
git pushUploads changes to GitHub
git pullDownloads latest changes

Example Workflow

$ git init

$ git add .

$ git commit -m "Initial Commit"

$ git push origin main

Git Branching

Branches allow developers to work on different features independently without affecting the main project code.

Branching Workflow

Main Branch
Feature Branch
Bug Fix Branch
Merge Changes into Main
$ git branch feature-login

$ git checkout feature-login

Pull Requests

A pull request (PR) is a request to merge changes from one branch into another branch on GitHub.

Pull requests are commonly used in open-source projects and team-based software development for reviewing code before merging.

Code Review

Team members review submitted code changes.

Discussion

Developers discuss improvements and fixes.

Merge

Approved changes are merged into main branch.


Git vs GitHub

GitGitHub
Version control systemCloud hosting platform
Works locallyWorks online
Tracks code historyEnables collaboration

Summary

In this chapter, we explored Git, GitHub, repositories, version control workflows, Git commands, branching, pull requests, and collaboration techniques. These concepts are essential for modern software development and DevOps practices.