Git Basics for DevOps Engineers

🧰 Git Basics for DevOps Engineers

🔧 1. Core Git Concepts

Concept Description

Repository A project's history and code base tracked by Git.

Working Directory The files in your local checkout.

Staging Area Where you prepare changes before committing.

Commit A snapshot of your changes with a message.

Branch A separate line of development.

Remote A version of your repo on another server (e.g., GitHub, GitLab).


🚀 2. Common Git Commands

bash

Copy

Edit

# Clone a repository

git clone https://github.com/user/repo.git


# Check repo status

git status


# Add changes to staging area

git add .


# Commit staged changes

git commit -m "Your commit message"


# Push changes to remote

git push origin main


# Pull changes from remote

git pull origin main

🌿 3. Branching for DevOps

Branching allows safe parallel work, useful in CI/CD pipelines or infrastructure-as-code (IaC) development.


bash

Copy

Edit

# Create and switch to new branch

git checkout -b feature/terraform-aws


# Push branch to remote

git push -u origin feature/terraform-aws

✅ Use meaningful branch names like feature/, bugfix/, hotfix/, or infra/.


🧩 4. Merge and Rebase

bash

Copy

Edit

# Merge a feature branch into main

git checkout main

git merge feature/terraform-aws


# Rebase a feature branch onto main

git checkout feature/terraform-aws

git rebase main

💡 Use merge for collaboration, rebase for a cleaner history before final merges.


🔄 5. Working with Remotes

bash

Copy

Edit

# Add a new remote (e.g., for GitHub)

git remote add origin https://github.com/user/repo.git


# See current remotes

git remote -v

💥 6. Undoing Things

bash

Copy

Edit

# Undo changes in working directory

git checkout -- filename


# Unstage a file

git reset HEAD filename


# Amend last commit

git commit --amend -m "Updated commit message"

📦 7. .gitignore

Prevent sensitive or unnecessary files (like secrets or terraform.tfstate) from being committed:


.gitignore


bash

Copy

Edit

*.tfstate

*.log

.env

secrets/

node_modules/

⚙️ 8. Git in CI/CD Pipelines

Trigger builds from specific branches or tags.


Automate deployments from main, dev, or release/*.


Use Git hooks or CI/CD tools (e.g., GitHub Actions, GitLab CI, Jenkins).


✅ 9. Best Practices for DevOps

✅ Keep commits atomic and meaningful


✅ Regularly pull to stay up to date


✅ Use Pull Requests/Merge Requests for reviews


✅ Never commit secrets or credentials


✅ Automate testing/deployment via pipelines

Learn DevOps Course in Hyderabad

Read More

Best Monitoring Tools for DevOps Teams

Introduction to Prometheus and Grafana

Terraform vs Ansible: Which to Choose and Why

Kubernetes 101: Orchestration Made Simple

Visit Our IHub Talent Training Institute in Hyderabad

Get Directions

Comments

Popular posts from this blog

Understanding Snowflake Editions: Standard, Enterprise, Business Critical

Why Data Science Course?

How To Do Medical Coding Course?