Git and DevOps - Version Control and Deployment for Web Developers
Git is the world's most widely used version control system. It allows developers to track code changes, collaborate in teams, and roll back to previous versions.
DevOps bridges the gap between development and operations, enabling teams to ship code faster and more reliably using automation pipelines and containerization.
This guide covers Git fundamentals, GitHub workflows, CI/CD basics, and Docker for web developers.
Git Fundamentals
Git tracks changes to files in a repository. Every change is captured in a commit, which forms a history of your project over time.
# Initialize a new repository
git init
# Clone an existing repository
git clone https://github.com/user/repo.git
# Check status of working directory
git status
# Stage changes
git add . # Stage all changes
git add src/index.js # Stage specific file
# Commit staged changes
git commit -m "feat: add user authentication"
# Push to remote repository
git push origin main
# Pull latest changes from remote
git pull origin main
Branching and Merging
Branches allow developers to work on features or fixes in isolation without affecting the main codebase. The most common strategy is Git Flow or trunk-based development.
# Create and switch to a new branch
git checkout -b feature/user-login
# List all branches
git branch -a
# Merge feature branch into main
git checkout main
git merge feature/user-login
# Delete merged branch
git branch -d feature/user-login
# Rebase for a cleaner history
git checkout feature/user-login
git rebase main
# View commit history as a graph
git log --oneline --graph --all
Pull requests (PRs) on GitHub and GitLab provide a code review workflow before merging feature branches into the main branch.
GitHub Actions - CI/CD Pipelines
GitHub Actions lets you automate build, test, and deployment workflows directly from your GitHub repository using YAML configuration files.
# .github/workflows/ci.yml
name: Node.js CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Build project
run: npm run build
Docker Basics for Web Developers
Docker packages your application and its dependencies into a container — a lightweight, portable unit that runs consistently across any environment.
# Use official Node.js image
FROM node:20-alpine
# Set working directory
WORKDIR /app
# Copy package files and install dependencies
COPY package*.json ./
RUN npm ci --only=production
# Copy source code
COPY . .
# Build the application
RUN npm run build
# Expose port
EXPOSE 3000
# Start the application
CMD ["node", "dist/server.js"]
Docker Compose lets you define and run multi-container applications, such as a web app with a database and a Redis cache, all in one config file.
DevOps Best Practices
- Write meaningful commit messages using Conventional Commits (feat:, fix:, docs:)
- Use .gitignore to exclude node_modules, build artifacts, and .env files
- Protect your main branch with required PR reviews and status checks
- Automate testing on every push with CI pipelines
- Use environment variables for secrets — never commit API keys or passwords
- Tag releases with semantic versioning (v1.0.0, v1.1.0, v2.0.0)
- Monitor deployed applications with logging and uptime alerts
Conclusion
Git and DevOps skills are essential for every modern web developer. Version control, automated testing, and deployment pipelines help teams ship code faster and with fewer bugs.
Start with Git fundamentals, adopt GitHub Actions for CI/CD, and containerize your applications with Docker to build a professional and scalable development workflow.
Codecrown