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
| Concept | Definition |
|---|---|
| Repository (Repo) | Storage location where project files and history are kept |
| Version Control | System that records file changes over time |
| Commit | Snapshot of changes made in the project |
| Branch | Parallel version of the project used for feature development |
| Merge | Combining changes from different branches |
| Remote Repository | Online 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
| Command | Description |
|---|---|
git init | Initialize a new repository |
git add . | Add all files to staging area |
git commit -m "msg" | Save changes with a message |
git status | View working directory status |
git log | View commit history |
git branch | List 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 pull | Fetch and merge remote changes |
git push | Upload local commits to remote |
git remote -v | View remote repository URLs |
Git & Version Control — Notes PDF
Week 5 & 6 · Repository, Branching, Commits & GitHub