Monday, June 16, 2025

thumbnail

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

Subscribe by Email

Follow Updates Articles from This Blog via Email

No Comments

About

Search This Blog

Powered by Blogger.

Blog Archive