← Back to DevOps
© 2025 sampathirao yoganandh
Week 5 & 6 · CO-2

Git & Version Control

Git VCS — Repository, Staging, Commits, Branching, Merging, Push to GitHub  CO-2

What is Git?

Git is a Distributed Version Control System (DVCS) used to track changes in source code during software development. It allows multiple developers to work simultaneously without overwriting each other's work.

Tools Required Git — Distributed version control system  |  GitHub — Remote repository hosting  |  Git Bash / Terminal — Command execution

Key Concepts

ConceptDefinition
Repository (Repo)Storage location where project files and history are kept
Version ControlSystem that records file changes over time
CommitSnapshot of changes made in the project
BranchParallel version of the project used for feature development
MergeCombining changes from different branches
Remote RepositoryOnline repo (GitHub) used for backup and collaboration

Architecture Flow

Git Data Flow Working Directory → git add → Staging Area → git commit → Local Repository → git push → Remote Repository (GitHub)

Step-by-Step Procedure

Step 1: Install Git

sudo apt install git -y
git --version

Step 2: Configure Git Username and Email

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

Step 3: Create a New Repository

mkdir myproject
cd myproject
git init

Step 4: Add Files to Staging Area

touch file1.txt
git add file1.txt
# Or add all files at once:
git add .

Step 5: Commit Changes

git commit -m "Initial commit"

Step 6: Check Repository Status

git status
git log

Step 7: Create and Switch Branch

git branch feature1
git checkout feature1
# Or create and switch in one command:
git checkout -b feature1

Step 8: Merge Branch

git checkout main
git merge feature1

Step 9: Connect to GitHub Repository

git remote add origin https://github.com/username/repo-name.git

Step 10: Push Code to GitHub

git push -u origin main
CI/CD Integration In DevOps pipelines, every git push to GitHub automatically triggers a Jenkins build. This is the foundation of Continuous Integration.

Common Git Commands

CommandDescription
git initInitialize a new repository
git add .Add all files to staging area
git commit -m "msg"Save changes with a message
git statusView working directory status
git logView commit history
git branchList all branches
git checkout <branch>Switch to a branch
git merge <branch>Merge branch into current branch
git clone <url>Copy a remote repository locally
git pullFetch and merge remote changes
git pushUpload local commits to remote
git remote -vView remote repository URLs
📄

Git & Version Control — Notes PDF

Week 5 & 6 · Repository, Branching, Commits & GitHub

⬇ Download PDF