Git & Github Handbook
Tuesday, August 5, 2025 10:45 AM
What is Git and Github ?
Git: A distributed version control system that tracks code changes and enables collaboration among
developers.
GitHub: An online platform for hosting Git repositories, sharing code, and collaborating with others
using Git.
----------------------------------------------------------------------------------------------------------------------------------------
Git branching :-
What is a Git Branch?
Ans:- A branch in Git is a separate version of your code that allows you to:
• Work on new features
• Fix bugs
• Try experimental ideas Without affecting your main code (usually the main or master branch).
----------------------------------------------------------------------------------------------------------------------------------------
Why Use a Branching Strategy?
A branching strategy is a set of rules or a workflow your team follows to:
• Keep code organized
• Control what gets deployed
• Avoid bugs in production
• Make collaboration easier
----------------------------------------------------------------------------------------------------------------------------------------
Common Git Branches in a Team Workflow
Branch Name Purpose
main / master Stable production-ready code
develop Ongoing development (integration)
feature/* New features under development
release/* Preparing for a new production release
hotfix/* Emergency fixes for production bugs
----------------------------------------------------------------------------------------------------------------------------------------
Git Branching Strategy: Git Flow Model
This is a widely-used strategy for managing branches.
1. main branch (or master)
• Always contains stable production code
• You don’t develop directly here
• Releases and hotfixes get merged here
2. develop branch
• Integrates features before going to production
• All feature branches are merged here
• When you're ready to release → merge into release or main
3. feature/<name> branches
• Used for building a new feature
• Created from: develop
• Merged into: develop
Example:
git checkout develop
git checkout -b feature/login-page
4. release/<version> branches
• Prepares a release version for production
• Final polishing: bug fixes, tests, version bumping
• Created from: develop
• Merged into: main and develop
Example:
git checkout develop
git checkout -b release/1.0.0
5. hotfix/<name> branches
• For fixing critical bugs in production
• Created from: main
• Merged into: main and develop
Example:
git checkout main
git checkout -b hotfix/urgent-crash-fix
----------------------------------------------------------------------------------------------------------------------------------------
Summary Table:
Branch Created From Merged Into Use Case
main N/A hotfix/release Production-ready code
develop main feature/release Integration branch
feature develop develop New features
release develop main & develop Final testing before release
hotfix main main & develop Emergency fixes in production
----------------------------------------------------------------------------------------------------------------------------------------
Git & GitHub Command Cheat Sheet :
1. Repository Initialization & Configuration
Command Description Example
git init Initialize a new Git git init
repository
git config Set user info or aliases git config --global user.name "your-name"
git clone <repo-url> Clone remote git clone https://github.com/<github-
repository username>/<repo-name>.git
2. Staging & Committing
Command Description Example
git status See current changes git status
git add . Stage all changes git add .
git add <file> Stage specific file git add Jenkinsfile
git commit -m "message" Commit staged changes git commit -m "Added Dockerfile"
3. Branching & Merging
Command Description Example
git branch View all branches git branch
git branch <name> Create new branch git branch feature/login
git checkout <branch> Switch to branch git checkout feature/login
git checkout -b <branch> Create & switch git checkout -b hotfix/bug-123
git merge <branch> Merge into current git checkout maingit merge feature/login
branch
git branch -d <branch> Delete branch git branch -d feature/login
4. Working with Remote
Command Description Example
git remote -v List remotes git remote -v
git remote add origin Add remote git remote add origin https://github.com/github-
<url> username/project.git
git push -u origin main Push to GitHub git push -u origin main
git pull origin main Pull latest code git pull origin main
5. Rebasing & Cherry-Picking
Command Description Example
git rebase <branch> Reapply commits on top git rebase main
git cherry-pick <commit> Apply specific commit git cherry-pick abc1234
6. Stashing & Cleaning
Command Description Example
git stash Save local changes git stash
temporarily
git stash pop Apply and remove stash git stash pop
git clean -fd Remove untracked files git clean -fd
7. Collaboration (PRs, Forks, etc.)
Command Description Example
Fork Repo (GitHub) Copy project under your Click “Fork” button on GitHub
account
git remote add Add original repo git remote add upstream
upstream <url> https://github.com/original/devops.git
git fetch upstream Fetch upstream updates git fetch upstream
git merge Merge upstream into git merge upstream/main
upstream/main your fork
PR (Pull Request) Contribute changes to Push to your branch on fork, then click "Pull
original Request" in GitHub UI
8. Viewing History & Logs
Command Description Example
git log View commit history git log --oneline --graph --all
git show <commit> Show commit details git show abc1234
git diff See unstaged changes git diff
git diff --staged See staged changes git diff --staged
9. Conflict Resolu on
Command Description Example
Manual Resolution During git pull or git merge, Use VSCode or terminal to fix conflicts
resolve files manually
git add <resolved-file> Mark conflict as resolved git add app.py
git commit Commit the resolution git commit -m "Resolved conflict"
10. DevOps-Specific Git Use Cases
Scenario Git Usage
CI/CD Pipelines Code pushed to main triggers Jenkins/GitHub Actions
IaC Repos Store Terraform, Ansible, Helm, K8s YAMLs with version control
Versioned Deployments Use tags: git tag v1.0.0 + git push origin --tags
Rollback Checkout previous commit: git checkout abc1234
Tag for Release git tag -a v2.0 -m "Stable release"git push origin v2.0
Bonus Tips for Real-World DevOps
• Use .gitignore to exclude Terraform state files, credentials, node_modules, etc.
• Always create a feature branch before pushing changes.
• Use pull requests for review even in internal team repos.
• Keep commit messages meaningful and atomic (fix: updated k8s manifest).