DevOps Job Ready Program

Learn • Practice • Get Hired

Git Installation Guide

Introduction

Git

Git is a distributed version control system (DVCS) used to track changes in source code and other files during software development. It enables developers to work on projects efficiently, maintain version history, collaborate with team members, and restore previous versions when needed. Git was created by Linus Torvalds in 2005 to support the development of the Linux kernel. Key Features of Git • Tracks changes made to files over time. • Allows multiple developers to work on the same project simultaneously. • Supports branching and merging for parallel development. • Maintains a complete history of all changes (commits). • Enables rollback to previous versions if errors occur. • Works offline without requiring an internet connection. • Fast, secure, and widely used in DevOps and software development. Example A developer modifies a web application and saves the changes using Git. If a bug is introduced, Git allows the developer to revert to a previous working version without losing project history.

GitHub

GitHub GitHub is a cloud-based repository hosting platform that uses Git for version control. It provides an online location to store Git repositories and offers collaboration features such as pull requests, code reviews, issue tracking, project management, and automation through GitHub Actions. GitHub is widely used by individuals, open-source communities, and organizations to manage software projects. Key Features of GitHub • Hosts Git repositories in the cloud. • Enables collaboration among developers worldwide. • Supports public and private repositories. • Provides Pull Requests for code review and merging. • Includes Issues for bug tracking and feature requests. • Offers GitHub Actions for CI/CD automation. • Integrates with many DevOps and cloud tools. • Maintains backups and repository security. Example A team develops a web application using Git locally. Each developer pushes their code to GitHub, where team members review changes through Pull Requests before merging them into the main branch.

Installation varies depending on your Operating System. Always verify the installation after completion using git --version.

  • Windows: Download the installer from git-scm.com and follow the default prompts in Git Bash.
  • Ubuntu/Debian: sudo apt update && sudo apt install git -y
  • CentOS/RHEL: sudo yum install git -y

Git & GitHub Cheat Sheet

Command Description
git init Initialize a new Git repository locally.
git add . Stage all changes for the next commit.
git commit -m "message" Save changes with a descriptive message.
git push origin main Upload local commits to GitHub.
git pull origin main Download and merge changes from GitHub.

Pro Tip:

Always use git status to check which files are changed before committing!

Understanding Git Configuration Levels

Git allows you to set preferences at different levels. When settings overlap, Local overrides Global, and Global overrides System.

Level Scope Configuration File Location
System Affects every user on the machine. /etc/gitconfig
Global Affects only your specific user account. ~/.gitconfig
Local Affects only the current repository. .git/config

Essential Identity Setup:

Before making your first commit, set your identity:

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

Summary

Git is the engine that tracks your code history, while GitHub is the platform that enables team collaboration. Git installation prepares your computer for version control, while configuration personalizes Git with your identity and preferences. Proper configuration ensures that every commit contains accurate author information and provides a consistent development environment. Once Git is installed and configured, you are ready to create repositories, track changes, collaborate with teams, and integrate with platforms such as GitHub.

Repository Management

Introduction

A repository (repo) is the core storage unit in Git. Managing it effectively involves initializing, cloning, and maintaining the state of your project files.

A Git repository is a directory that contains your project files along with a hidden .git folder. The .git directory stores all the version history, branches, commits, tags, and configuration information for the project. There are two types of repositories:

  • • Local Repository – Stored on your computer.
  • • Remote Repository – Hosted on platforms like GitHub, GitLab, or Bitbucket.

What is a Git Repository?

A Git repository is a virtual directory that tracks changes to your project files. It contains the project's entire history and metadata in a hidden .git folder. There are two main ways to start a repository:

  • Local Initialization: Starting a new project on your computer.
  • Cloning: Downloading an existing project from a remote host like GitHub.

Common Repository Management Commands

These commands are the "bread and butter" of a developer's daily workflow:

  • git init: Initializes a new, empty Git repository in the current folder.
  • git clone [url]: Creates a local copy of an existing remote repository.
  • git status: Displays the state of the working directory and the staging area (shows which files are tracked or untracked).
  • git add [file]: Moves changes from the working directory to the Staging Area.
  • git commit -m "message": Permanently saves the staged changes to the repository history.
  • git remote add origin [url]: Links your local repo to a remote server (like GitHub).
  • git push -u origin main: Uploads your local commits to the remote repository.

Conclusion

Repository management is the foundation of version control. By understanding the distinction between the working directory, the staging area, and the commit history, you gain full control over your project's evolution. Consistent use of these commands ensures that your code remains organized, shareable, and recoverable at any point in time.

Repository Management is the foundation of working with Git. It involves creating repositories, tracking changes, committing updates, managing files, viewing history, and synchronizing with remote repositories. Proper repository management improves collaboration, maintains a complete history of project changes, and ensures that source code remains secure, organized, and easy to maintain.

<

Branching Strategy in Git

Introduction

A Branching Strategy is a workflow approach to manage different versions of code. It allows parallel development without affecting the stable production codebase.

A Branching Strategy is a workflow approach used in Git to manage different versions of source code during software development. Branches allow developers to work on new features, bug fixes, testing, and releases without affecting the main production code. A well-defined branching strategy improves collaboration, reduces conflicts, and supports efficient CI/CD (Continuous Integration and Continuous Deployment) workflows used in DevOps environments.

What is a Git Branch?

A Git branch is an independent line of development. Each branch maintains its own commit history, which can later be merged back into the main line.

Common Branching Strategies

1. Git Flow Strategy

A structured model ideal for release-heavy projects. It uses specific branches: main (stable), develop (integration), feature/*, release/*, and hotfix/*.

2. GitHub Flow

A lightweight, branch-based workflow that supports teams who deploy regularly. It relies on Pull Requests for code review before merging into main.

3. Trunk-Based Development

Focuses on a single main branch with short-lived feature branches, ideal for CI/CD pipelines to avoid "merge hell."

4. GitLab Flow

Combines Git Flow and GitHub Flow, utilizing environment-specific branches (staging/production) for enterprise applications.

Branch Management Commands

TaskCommand
Create & Switchgit switch -c [name]
List Branchesgit branch -a
Mergegit merge [branch]
Delete Localgit branch -d [name]

Branching Strategy in DevOps

In a modern DevOps lifecycle, branching is the trigger for automated pipelines:

  • CI Pipeline: Automated testing on every Pull Request.
  • Deployment: Merging to main triggers auto-deployment to production via Jenkins, Docker, or Kubernetes.

Recommendation: For most DevOps teams, GitHub Flow combined with CI/CD is the most efficient and scalable choice.

Conclusion

A Git Branching Strategy defines how teams create, manage, review, and merge code changes. Common strategies include Git Flow, GitHub Flow, GitLab Flow, and Trunk-Based Development. Choosing the right strategy helps teams maintain stable code, improve collaboration, and automate software delivery through DevOps pipelines.

Git Merge & Rebase

Introduction

Both Merge and Rebase are Git commands used to integrate changes from one branch into another branch. They combine different development histories but work in different ways.

1. Git Merge

Definition: Git Merge combines the changes from one branch into another branch by creating a new merge commit. It preserves the complete history of both branches.

Syntax: git merge <branch-name>

Example:
Suppose we have:
main
|
A---B
\
C---D feature
After merging:
main
|
A---B---------M
\ /
C-----D
M = Merge Commit

Steps:

  • Switch to the branch where you want changes: git checkout main
  • Merge feature branch: git merge feature
  • Push changes: git push origin main

Advantages of Git Merge

  • ✅ Keeps complete project history
  • ✅ Safe for shared/public branches
  • ✅ Easy to understand
  • ✅ Does not modify existing commits

Disadvantages

  • ❌ Creates additional merge commits
  • ❌ History can become complex in large projects

2. Git Rebase

Definition: Git Rebase moves or reapplies your branch commits on top of another branch. It creates a cleaner, linear project history.

Syntax: git rebase <branch-name>

Example:
Before Rebase:
main
|
A---B---C
\
D---E feature
After Rebase:
main
|
A---B---C---D'---E'
The feature branch commits are rewritten on top of the latest main branch.

Steps:

  • Switch to feature branch: git checkout feature
  • Update branch: git fetch origin
  • Rebase with main: git rebase main
  • Push changes: git push origin feature
  • If history was changed: git push --force

Merge vs Rebase Comparison

FeatureMergeRebase
PurposeCombine branchesMove commits to new base
HistoryPreserves historyRewrites history
Creates commitYesNo
History styleNon-linearLinear
Safe for public branchesYesUsually no
Best forTeam integrationCleaning feature branches
Commandgit mergegit rebase

When to Use Git Merge

Use Merge when: Working with shared branches, multiple developers collaborate, you want to preserve complete history, or merging production releases.

Example: feature branch → main branch
Command: git checkout main, git merge feature

When to Use Git Rebase

Use Rebase when: Updating your personal feature branch, cleaning commit history, preparing code before a Pull Request, or keeping Git history simple.

Example: feature branch → latest main changes
Command: git checkout feature, git rebase main

DevOps / CI-CD Best Practice

A common DevOps workflow:
Developer -> Feature Branch -> git rebase main -> Pull Request -> Code Review -> Merge into Main -> CI/CD Pipeline -> Production Deployment

Important Rule: ⚠️ Never rebase shared branches like main, master, or production. Avoid git rebase main on a branch that many developers are using. Rebase is best for your own local feature branches.

Useful Commands

  • Check branch history: git log --oneline --graph --all
  • Abort merge: git merge --abort
  • Abort rebase: git rebase --abort
  • Continue rebase: git rebase --continue

Summary

  • Merge = Combine branches safely and preserve history
  • Rebase = Rewrite history and create a clean linear timeline
  • For enterprise DevOps teams: Rebase feature branches + Merge reviewed code into main branch

Git Pull Requests (PR)

Introduction

A Pull Request (PR) allows developers to request that their code changes be reviewed and merged into another branch. It is a collaboration and code review workflow built on top of Git.

Purpose of Pull Requests:

  • ✅ Review code before merging
  • ✅ Detect bugs and security issues
  • ✅ Discuss improvements
  • ✅ Run automated CI/CD tests
  • ✅ Maintain code quality & track approvals

Pull Request Workflow

The standard development path involves: Clone -> Feature Branch -> Develop -> Commit -> Push -> Create PR -> Review -> Merge -> Deploy.

Creating a PR (Step-by-Step):

  1. Clone: git clone https://github.com/company/project.git
  2. Branch: git checkout -b feature-login
  3. Code & Commit: git add . followed by git commit -m "Added user login feature"
  4. Push: git push origin feature-login
  5. Create PR: On GitHub/GitLab, select source feature-login and target main.

The Review Process

  1. Code Review: Senior developers check quality, security, and standards.
  2. Automated Testing: CI/CD tools verify the build, unit tests, and security scans.
  3. Approval: Final sign-off from Lead/QA/DevOps.
  4. Merge Options: Merge Commit, Squash Merge, or Rebase Merge.

Best Practices

  • Keep PRs Small: Focus on one task per PR.
  • Clear Titles: Use descriptive names (e.g., "Add AWS S3 backup automation").
  • Add Descriptions: Explain the purpose, changes, and testing results.
  • Link Issues: Use Fixes #245 to track bugs.
  • Never Push Directly to Main: Always go through the PR/Review process.

Pull Requests in DevOps

PRs are the heart of DevOps automation. A PR creation triggers an automated pipeline:

Developer PR -> GitHub/GitLab -> CI Pipeline (Build, Test, Security Scan) -> Approval -> Merge -> CD Deployment -> Production
        

Common PR Commands:

git branch -a | git pull origin main | git checkout -b feature-name | git push origin feature-name

Pull Request Summary

FeatureDescription
PurposeCode review before merging
Created FromFeature branch
AutomationCI/CD pipelines
Final StepMerge into main

GitHub Actions

Introduction

Definition: GitHub Actions is a CI/CD automation platform provided by GitHub that allows developers and DevOps engineers to automatically build, test, deploy, and manage software workflows directly from a GitHub repository.

It uses YAML configuration files to define automated workflows that run when specific events occur, such as:

  • Code push
  • Pull Request creation
  • New release
  • Scheduled time (cron jobs)
  • Manual execution

Why Use GitHub Actions?

GitHub Actions helps teams:

  • ✅ Automate software build processes
  • ✅ Run automated tests
  • ✅ Perform security scans
  • ✅ Build Docker images
  • ✅ Deploy applications to cloud platforms
  • ✅ Automate DevOps tasks
  • ✅ Reduce manual deployment effort

GitHub Actions Architecture

The main components are:

Repository
    |
.github/workflows/
    |
Workflow YAML File
    |
   Jobs
    |
   Steps
    |
  Actions / Commands
    |
  Runner Machine

Main Components of GitHub Actions

1. Workflow

A workflow is an automated process defined in a YAML file. Location: .github/workflows/. A workflow defines when it runs, what jobs execute, and what steps are performed.

2. Events (Triggers)

Events define when the workflow starts.

  • Push Event: on: push: branches: - main (Runs when code is pushed to the main branch).
  • Pull Request Event: on: pull_request: branches: - main (Runs when a Pull Request is created).
  • Schedule Event: on: schedule: - cron: "0 0 * * *" (Runs automatically at scheduled times).

3. Jobs

A workflow contains one or more jobs. Example: jobs: build: runs-on: ubuntu-latest. Jobs run on Ubuntu, Windows, or macOS.

4. Steps

Steps are individual tasks inside a job.

5. Actions

Actions are reusable automation components (e.g., uses: actions/checkout@v4).

6. Runner

A Runner is the server that executes GitHub Actions workflows. Types: GitHub-hosted runners (Ubuntu, Windows, macOS) and Self-hosted runners (AWS EC2, On-premises Linux, Private infrastructure).

Basic GitHub Actions Workflow

Example: .github/workflows/build.yml

name: Node.js CI Pipeline
on:
  push:
    branches:
      - main
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout Code
      uses: actions/checkout@v4
    - name: Setup Node
      uses: actions/setup-node@v4
      with:
        node-version: 20
    - name: Install Packages
      run: npm install
    - name: Run Tests
      run: npm test

GitHub Actions CI/CD Pipeline

Flow: Developer → Git Push → GitHub Repository → GitHub Actions Trigger → Build, Test, Security Scan → Docker Image Build → Push to Registry → Deploy to AWS/Kubernetes → Production

GitHub Actions with Docker

Example workflow:

name: Docker Build
on:
  push:
    branches:
      - main
jobs:
  docker:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - name: Build Docker Image
      run: docker build -t myapp .
    - name: Login Docker Hub
      run: docker login
    - name: Push Image
      run: docker push myapp

GitHub Actions with AWS Deployment

Common AWS integrations: Amazon EC2, Amazon S3, Amazon Elastic Container Service (ECS), Amazon Elastic Kubernetes Service (EKS).

GitHub Actions vs Jenkins

FeatureGitHub ActionsJenkins
PlatformGitHub integratedStandalone server
InstallationNo installation requiredRequires setup
ConfigurationYAMLGroovy
HostingGitHub Cloud / Self-hostedSelf-hosted
PluginsMarketplace ActionsLarge plugin ecosystem
Best ForGitHub-based projectsEnterprise CI/CD

GitHub Actions Best Practices

  1. Use Secrets: Never store passwords in plain text. Use ${{ secrets.DB_PASSWORD }}.
  2. Use Branch Protection: Protect main, production, release branches.
  3. Cache Dependencies: Use actions/cache@v4 to improve pipeline speed.
  4. Separate Environments: Development → Testing → Staging → Production.

Summary

GitHub Actions = Automation engine for GitHub repositories.

  • Workflow → Complete automation process
  • Event → Trigger condition
  • Job → Group of tasks
  • Step → Individual commands
  • Action → Reusable automation component
  • Runner → Machine executing the workflow

For a DevOps Engineer, GitHub Actions is an essential CI/CD skill used for automating modern cloud-native application deployments.

GitLab Overview

Introduction

Definition: GitLab is a complete DevOps platform that provides tools for the entire software development lifecycle, including source code management, version control, CI/CD automation, security testing, monitoring, and application deployment.

Unlike traditional tools that require multiple integrations, GitLab provides a single platform where teams can plan, create, test, deploy, and monitor applications. GitLab is widely used by DevOps teams for implementing DevOps automation and CI/CD pipelines.

GitLab DevOps Lifecycle

GitLab follows the complete DevOps lifecycle:

Plan | Create | Verify | Package | Release | Configure | Monitor | Secure

Key Features of GitLab

1. Git Repository Management

GitLab provides Git-based source code management similar to GitHub. Developers can create repositories, store source code, manage branches, track changes, review code, and manage permissions.

Example: git clone https://gitlab.com/company/project.git

2. GitLab Projects

A Project is a repository where source code, issues, pipelines, and documentation are stored.

Company Project
       |
       ├── Source Code
       ├── Issues
       ├── Merge Requests
       ├── CI/CD Pipeline
       └── Documentation

3. GitLab Branching Strategy

Common enterprise workflow: main | develop | feature | release | hotfix

BranchPurpose
main/masterProduction code
developDevelopment testing
featureNew features
releaseRelease preparation
hotfixEmergency fixes

4. Merge Requests (MR)

GitLab uses Merge Requests instead of Pull Requests. A Merge Request allows developers to submit code changes, request reviews, discuss improvements, run automated tests, and merge approved code.

Workflow: Developer → Feature Branch → Merge Request → Code Review → CI/CD Pipeline → Merge into Main

5. GitLab CI/CD

GitLab has built-in CI/CD automation. Configuration file: .gitlab-ci.yml

stages:
 - build
 - test
 - deploy

build_job:
 stage: build
 script:
   - echo "Building application"

test_job:
 stage: test
 script:
   - echo "Running tests"

deploy_job:
 stage: deploy
 script:
   - echo "Deploying application"

GitLab Pipeline Architecture

Code Push → GitLab CI/CD Trigger → (Build | Test | Security Scan | Deploy) → Production

6. GitLab Runner

A GitLab Runner executes CI/CD jobs. Types: Shared Runner (Provided by GitLab) and Specific Runner (Dedicated to a project/group).

7. GitLab Container Registry

GitLab provides a built-in Docker image registry. Workflow: Developer → Docker Build → GitLab Container Registry → Kubernetes Deployment.

8. GitLab Kubernetes Integration

GitLab integrates with Kubernetes for automated deployments. Common environments: Development, Staging, Production.

9. GitLab Security Features

GitLab provides DevSecOps capabilities: SAST, DAST, Dependency Scanning, Container Scanning, and Secret Detection.

10. GitLab Issue Tracking

GitLab includes project management features: Issues, Labels, Milestones, Boards, and Roadmaps.

Example: Issue #101 | Title: Fix Login Authentication Bug | Status: In Progress

GitLab Architecture

Users → GitLab Web UI → (Git Repository | CI/CD Engine | GitLab Runner) → Deployment → Cloud/Kubernetes/Server

GitLab vs GitHub

FeatureGitLabGitHub
Git Repository
CI/CDBuilt-inGitHub Actions
Code ReviewMerge RequestPull Request
Container RegistryBuilt-inAvailable
Kubernetes IntegrationStrongStrong
DevSecOpsBuilt-inThrough tools
Self-hostedYesYes

GitLab in DevOps Workflow

Developer → GitLab Repository → Merge Request → GitLab CI/CD Pipeline → Docker Build → Container Registry → Kubernetes/Cloud → Production

Common GitLab Commands

  • Clone repository: git clone <repository-url>
  • Check status: git status
  • Create branch: git checkout -b feature-name
  • Push changes: git push origin feature-name
  • Pull latest code: git pull origin main

GitLab Best Practices

✅ Use protected branches | ✅ Enable Merge Request approvals | ✅ Store credentials in CI/CD variables | ✅ Use automated testing pipelines | ✅ Integrate security scanning | ✅ Use Infrastructure as Code with Terraform | ✅ Use Docker and Kubernetes deployment automation

GitLab Summary

ComponentPurpose
Git RepositorySource code management
Merge RequestsCode review
GitLab CI/CDAutomation pipelines
GitLab RunnerExecutes jobs
Container RegistryStores Docker images
Kubernetes IntegrationApplication deployment
Security ToolsDevSecOps protection

GitLab is an all-in-one DevOps platform that enables organizations to manage the complete software delivery lifecycle — from source code to production deployment.

Git Best Practices

Introduction

Definition: Git Best Practices are recommended rules, workflows, and techniques that help development teams maintain clean code history, improve collaboration, reduce conflicts, and enable reliable CI/CD deployments. Following Git best practices is essential for DevOps engineers, software developers, and cloud teams working on enterprise projects.

1. Use Meaningful Commit Messages

Recommended Format: <Type>: Short description

TypePurpose
featNew feature
fixBug fix
docsDocumentation
refactorCode improvement
testTesting changes
choreMaintenance

2. Commit Small and Frequently

Avoid large commits. Benefits: Easier code review, troubleshooting, and better rollback capability.

3. Never Commit Directly to Main Branch

Recommended: Developer → Feature Branch → Pull/Merge Request → Code Review → main.

4. Use a Branching Strategy

Main enterprise workflow includes: main, develop, feature/*, bugfix/*, and hotfix/*.

5. Pull Latest Changes Before Starting Work

git checkout maingit pull origin maingit checkout -b feature-login

6. Use Pull Requests / Merge Requests

Never merge untested code. Workflow: Feature Branch → Pull Request → Code Review → CI/CD Testing → Merge.

7. Review Code Before Merging

Review for code quality, security, performance, standards, and documentation.

8. Keep Branches Updated

Use git merge main or git rebase main regularly to reduce conflicts.

9. Avoid Committing Sensitive Data

❌ Never commit passwords, API keys, or SSH keys. Use Environment variables or CI/CD secrets.

10. Use .gitignore Properly

Exclude files like node_modules/, .env, *.log, .terraform/.

11. Write Good README Documentation

Include description, installation, configuration, usage, and deployment process.

12. Tag Releases

Use Git tags for versions (e.g., v1.0.0) following the Major.Minor.Patch format.

13. Use Git Hooks

Automate checks (formatting, unit testing, security) before commits using pre-commit hooks.

14. Use Git Rebase Carefully

Good for personal feature branches; ⚠️ Avoid on shared/production branches.

15. Resolve Conflicts Carefully

Check git status, edit files, git add ., then git commit.

16. Use CI/CD Integration

Connect Git with GitHub Actions, GitLab CI/CD, or Jenkins.

17. Regularly Clean Repository

Remove unused branches: git branch -d and git fetch --prune.

Recommended DevOps Git Workflow

Clone → Feature Branch → Code Changes → Commit → Push → Pull Request → CI/CD Pipeline → Code Review → Merge to Main → Production Deployment.

Git Best Practices Checklist

PracticeRecommended
Meaningful commits
Small commits
Feature branches
Protected main branch
Code reviews
Pull/Merge Requests
Proper .gitignore
No secrets in Git
Automated CI/CD
Release tagging

Summary

Git Best Practices help teams build secure, maintainable, and scalable software delivery workflows. For a DevOps Engineer, the ideal Git workflow is: Feature Branch → Commit → Push → Pull Request → Review → CI/CD Pipeline → Merge → Production Deployment.

Real-World Team Collaboration Using Git

Introduction

Definition: Real-world Git team collaboration describes how multiple developers, DevOps engineers, testers, and project managers work together on the same software project using Git-based workflows. In professional environments, Git is used with platforms like GitHub, GitLab, and Bitbucket to manage source code, review changes, automate testing, and deploy applications.

Real-World Development Team Structure

                 Project Manager
                       |
                 Technical Lead
                       |
        -----------------------------
        |              |            |
     Developers     QA Team    DevOps Engineer
        |              |            |
        -----------------------------
                       |
                   Production

Typical Team Roles

  • 1. Developer: Writes application code, creates feature branches, commits changes, and creates Pull/Merge Requests. (Example: git checkout -b feature-payment)
  • 2. Tech Lead / Senior Developer: Reviews code, approves changes, maintains coding standards, and manages branch strategy.
  • 3. QA Engineer: Tests new features, verifies bug fixes, runs automated tests, and reports issues.
  • 4. DevOps Engineer: Manages CI/CD pipelines, automates deployments, maintains cloud infrastructure, and manages containers/Kubernetes.

Enterprise Git Workflow

                Production
                    |
                   main
                    |
              release branch
                    |
                 develop
                    |
        -------------------------
        |           |           |
    feature-1   feature-2    bug-fix

Step-by-Step Real-World Collaboration

  1. Project Setup: DevOps engineer initializes repository (git init).
  2. Clone: Developer downloads project (git clone <repository-url>).
  3. Create Feature Branch: Developers never work on main (git checkout -b feature-user-login).
  4. Development: Write code and check status (git status).
  5. Commit Changes: Create meaningful commits (git add ., git commit -m "feat: Add authentication").
  6. Push: Upload to remote server (git push origin feature-user-login).
  7. Pull/Merge Request: Create PR/MR with description, screenshots, and testing details.
  8. Code Review: Senior developer checks quality, security, and performance.
  9. Automated CI/CD Pipeline: Pipeline runs Build, Unit Tests, Security Scans, and Docker Build.
  10. Merge Code: After approval, git merge feature-user-login.
  11. Testing & Deployment: Development server → QA Testing → Production Release.

Best Practices & Real-World Examples

Handling Conflicts: If login.py changes by two devs, use git pull origin develop, fix conflicts, and commit.

DevOps Integration: Git → PR → CI/CD → Docker Build → Container Registry → Kubernetes → Production.

  • Branch Protection: Protect main/production branches.
  • Communication: Use Git Issues for tracking bugs and tasks.
  • Small Commits: Keep commits focused on individual tasks.
  • Code Reviews: Essential for quality and knowledge sharing.
  • Automate Everything: Testing, security, deployment, and infrastructure.

Real-World Example: Banking Application

Developer → Feature Branch → Merge Request → Security Review → Auto Testing → Approval → CI/CD Pipeline → Kubernetes → Production System

Summary

Real-world Git collaboration follows this pattern: Clone → Branch → Code → Commit → Push → Pull Request → Review → CI/CD Testing → Merge → Deploy.

Question & Answer

Git Fundamentals

1. What is Git?

Git is a distributed version control system used to track changes in source code, manage projects, and enable collaboration among developers.

2. Who created Git?

Git was created by Linus Torvalds in 2005 for Linux kernel development.

3. What is Version Control System (VCS)?

A Version Control System is a tool that records changes to files over time, allowing users to view history, restore previous versions, and collaborate.

4. What is GitHub?

GitHub is a cloud-based platform that hosts Git repositories and provides collaboration features such as pull requests, issues, and code reviews.

5. What is the difference between Git and GitHub?
GitGitHub
Version control softwareOnline Git repository hosting platform
Runs locallyCloud-based service
Manages code historyEnables collaboration
Command-line toolWeb interface + collaboration tools
6. Why is Git used in software development?

Git is used for: Tracking code changes, Team collaboration, Branch management, Code backup, Version history, and Deployment automation.

7. Is Git centralized or distributed?

Git is a distributed version control system because every developer has a complete copy of the repository history.

8. What are the benefits of Git?

Fast performance, Distributed workflow, Branching support, Secure code management, and Easy collaboration.

9. What is a Git Repository?

A Git repository is a storage location where Git tracks files, commits, branches, and project history.

10. What are the types of Git repositories?

Two types: Local Repository and Remote Repository.

Git Installation and Configuration

11. How do you install Git on Ubuntu?

sudo apt update
sudo apt install git

12. How do you check Git version?

git --version

13. How do you configure Git username?

git config --global user.name "Your Name"

14. How do you configure Git email?

git config --global user.email "email@example.com"

15. How do you view Git configuration?

git config --list

16. Why is Git username configuration required?

Git uses username and email information to identify the author of commits.

17. What is global Git configuration?

Global configuration applies to all repositories for a user. Location: ~/.gitconfig

18. What is local Git configuration?

Local configuration applies only to a specific repository. Location: .git/config

19. How do you change the default Git editor?

git config --global core.editor vim

20. How do you remove Git configuration?

git config --global --unset user.name

Git Repository Management

21. How do you create a new Git repository?

git init

22. What does git init do?

It initializes a new empty Git repository by creating a hidden .git directory.

23. What is the .git directory?

It stores repository metadata, commit history, branch information, and configuration.

24. How do you clone a repository?

git clone <repository_url>

25. Difference between git init and git clone?

git init creates a new empty repo, while git clone copies an existing one.

26. How do you check repository status?

git status

27. What is Git working directory?

The folder where you edit project files.

28. What is Git staging area?

Stores changes prepared for the next commit (using git add).

29. What is a commit?

A saved snapshot of project changes in Git history.

30. How do you create a commit?

git commit -m "message"

Git Commands

31. Add files to staging?

git add <filename>

32. Add all files?

git add .

33. View commit history?

git log

34. Short commit history?

git log --oneline

35. Compare file changes?

git diff

36. Remove file from staging?

git restore --staged <filename>

37. Delete a file from Git?

git rm <filename>

38. Rename a file?

git mv <old> <new>

39. Check remote repository?

git remote -v

40. Download latest changes?

git pull

Branching

41. What is a Git branch?

An independent line of development to work on features without affecting the main code.

42. Why are branches used?

For feature development, bug fixes, testing, and release management.

43. How to create a branch?

git branch <feature-name>

44. How to switch branches?

git checkout <branch-name>

45. Modern command to switch branch?

git switch <branch-name>

46. Create and switch branch?

git checkout -b <feature>

47. List branches?

git branch

48. What is the main branch?

Contains stable production-ready code (named 'main' or 'master').

49. What is feature branching?

A strategy where developers create separate branches for each new feature.

50. What is Git Flow?

A branching model for development, releases, and hotfixes.

Merge and Rebase

51. What is Git merge?

Combines changes from one branch into another.

52. What is Git rebase?

Moves commits from one branch to apply them on top of another.

53. Difference between merge and rebase?

Merge creates a merge commit (safer), whereas rebase creates a linear, cleaner history.

54. What is a merge conflict?

Occurs when Git cannot automatically combine changes.

55. How to resolve merge conflicts?

Open files, fix changes, git add ., and git commit.

GitHub

56. What is a GitHub Repository?

A GitHub repository is an online location where Git projects are stored and shared.

57. How do you create a GitHub repository?

Steps: Login to GitHub → Click "New Repository" → Enter repository name → Click "Create repository".

58. How do you connect local Git with GitHub?

git remote add origin <URL>

59. How do you push code to GitHub?

git push origin main

60. What is GitHub remote?

A remote is a connection between a local repository on your computer and an online repository on a server like GitHub.

Collaboration

61. What is a Pull Request?

A Pull Request (PR) is a formal request to merge your code changes from one branch into another branch.

62. Why are Pull Requests used?

They are used for code review, team collaboration, quality control, and an established approval process.

63. What is GitHub Issue?

Issues are a tool used to track bugs, tasks, and feature requests within a repository.

64. What is Code Review?

Code review is the process of peers checking code changes for quality, bugs, and security before they are merged into the main codebase.

65. What is Fork in GitHub?

A fork creates a personal, independent copy of another user's repository in your own GitHub account.

66. What is GitHub Organization?

An organization is a shared account that allows teams to manage multiple repositories and members efficiently.

67. What is README.md?

README.md is a Markdown file that provides project documentation, installation instructions, and usage details.

68. What is .gitignore?

.gitignore is a file that defines patterns of files or directories that Git should ignore (e.g., node_modules/, .env, *.log).

69. What is Git tag?

A tag marks a specific point in history as important, usually used for versioning. Example: git tag v1.0.

70. What is a Git release?

A release is a published, stable version of software on GitHub, often including release notes and binary assets.

Advanced Git

71. What is Git stash?

Git stash temporarily shelves (saves) unfinished changes in your working directory so you can switch branches cleanly. Command: git stash

72. How to restore stash?

Use git stash pop to restore the most recently stashed changes.

73. What is cherry-pick?

Cherry-pick copies a specific commit from one branch and applies it onto another branch. Command: git cherry-pick <commit_id>

74. What is Git reset?

Git reset moves the HEAD pointer to a previous commit, effectively "resetting" the branch state.

75. What is Git revert?

Git revert creates a new commit that explicitly performs the opposite of a previous commit, effectively reversing the changes while keeping the history intact.

76. Difference between reset and revert?

Reset: Changes the branch history (destabilizes shared branches).
Revert: Keeps history (safer for shared branches).

77. What is HEAD in Git?

HEAD is a pointer that refers to the current commit or the current branch you are working on.

78. What is detached HEAD?

A detached HEAD state occurs when you checkout a specific commit directly (by hash) instead of a branch name, meaning you are no longer on any branch.

79. What is Git remote fetch?

git fetch downloads the latest commits/data from the remote repository to your local machine without merging them into your current work.

80. Difference between fetch and pull?

Fetch: Downloads changes only (safe).
Pull: Downloads and merges changes into your current branch (equivalent to fetch + merge).

Git in DevOps

81. Why is Git important in DevOps?

Git provides the foundation for source code management and integrates seamlessly with CI/CD pipelines for automation.

82. Git with Jenkins?

Jenkins pulls source code from Git repositories to trigger automated builds and deployment tasks.

83. Git with Docker?

Docker images are often built automatically from Git repositories using containerization workflows.

84. Git with Kubernetes?

Kubernetes configuration files (manifests) are stored and managed in Git, often referred to as GitOps.

85. What is CI/CD?

Continuous Integration (CI) and Continuous Deployment (CD) automate the process of testing, building, and delivering software.

86. What is GitHub Actions?

It is an integrated automation platform directly inside GitHub for creating CI/CD workflows.

87. What is GitLab?

A comprehensive DevOps platform that includes Git repositories, CI/CD pipelines, security scanning, and project management.

88. What is GitLab CI/CD?

A feature in GitLab that automates the building, testing, and deployment of applications through YAML-based configuration.

89. What are Git best practices?

Write meaningful commit messages, use branches, perform code reviews, avoid committing secrets, and keep repositories clean.

90. How often should developers commit?

Developers should commit small, focused, and meaningful changes frequently to ensure a stable history.

Interview Questions

91. Explain Git workflow.

Working Directory → Staging Area → Repository → Remote Repository.

92. What happens during git push?

Git uploads local commits from your machine to a remote repository.

93. What happens during git pull?

Git downloads remote changes and merges them into the current local branch.

94. How to undo the last commit?

git revert HEAD

95. How to check who changed a line?

git blame <filename>

96. How to clone a private repository?

Using authentication methods like SSH keys or Personal Access Tokens (PAT).

97. What is SSH key authentication?

A method that allows secure communication between your machine and GitHub without needing to type your password every time.

98. What is GitHub Actions workflow file?

A YAML file stored in .github/workflows/ that defines the automation steps for your project.

99. Why should DevOps engineers learn Git?

It is the core of modern infrastructure automation, CI/CD, and collaborative deployment pipelines.

100. What is the role of Git in modern software development?

Git enables efficient collaboration, version tracking, automation, and reliable software delivery across development and production environments.