Beginner DevOps

Git & Version Control

Branching, merging, workflows, and collaboration.

Version Control with Git

Git is the industry-standard distributed version control system for tracking changes in source code.

Core Concepts

  • Repository: A directory tracked by Git
  • Commit: A snapshot of changes with a message
  • Branch: An independent line of development
  • Remote: A shared repository (GitHub, GitLab)

Essential Commands

# Initialize and clone
git init
git clone [url]

# Stage and commit
git add .
git commit -m "message"

# Branching
git branch feature-x
git checkout -b feature-x
git merge feature-x

# Remote operations
git push origin main
git pull origin main
git fetch

Branching Strategies

  • Git Flow: Feature, develop, release, hotfix branches
  • GitHub Flow: Simple main + feature branches
  • Trunk-Based: Short-lived branches, frequent merges

Best Practices

  • Write meaningful commit messages
  • Make small, focused commits
  • Pull before pushing
  • Use .gitignore for build artifacts