Skip to main content

📌 Essential Git Commands for DevOps

 

Essential Git Commands for DevOps


🔹 Understanding Git Commands
Git provides a powerful set of commands to manage source code efficiently. Here’s a list of all essential Git commands categorized based on their functionality.



🌍 Shape Your Future with AI & Infinite Knowledge...!!

🌐 Want to Generate Text-to-Voice, Images & Videos? 👉 http://www.ai.skyinfinitetech.com 📚 Read In-Depth Tech & Self-Improvement Blogs 👉 http://www.skyinfinitetech.com ▶ Watch Life-Changing Videos on YouTube 👉 https://www.youtube.com/@SkyInfinite-Learning 🔥 Transform Your Skills, Business & Productivity – Join Us Today! 🔥



1️⃣ Git Setup & Configuration


git --version # Check installed Git version git config --global user.name "Your Name" git config --global user.email "your@email.com" git config --global core.editor "vim" # Set default editor git config --list # View all Git configurations


2️⃣ Initializing & Cloning Repositories


git init # Initialize a new Git repository git clone <repo_URL> # Clone a remote repository


3️⃣ Staging & Committing Changes


git status # Check the status of working directory git add <file> # Add a specific file to staging git add . # Add all changes to staging git commit -m "Commit message" # Commit changes git commit -am "Commit message" # Add & commit in one step


4️⃣ Viewing Commit History


git log # View commit history git log --oneline # View short log format git log --graph --decorate --oneline --all # Visual commit history git show <commit_hash> # Show details of a specific commit


5️⃣ Branching & Merging


git branch # List all branches git branch <branch_name> # Create a new branch git checkout <branch_name> # Switch to another branch git checkout -b <branch_name> # Create & switch to a new branch git merge <branch_name> # Merge another branch into the current one git branch -d <branch_name> # Delete a branch


6️⃣ Working with Remote Repositories


git remote -v # View remote repositories git remote add origin <repo_URL> # Connect local repo to a remote git push origin <branch> # Push changes to remote git pull origin <branch> # Pull latest changes from remote git fetch # Fetch changes without merging git clone <repo_URL> # Clone a repository


7️⃣ Undoing Changes (Reset, Revert, Restore)


git reset --soft HEAD~1 # Undo last commit but keep changes staged git reset --mixed HEAD~1 # Undo last commit but keep changes unstaged git reset --hard HEAD~1 # Undo last commit and discard changes git revert <commit_hash> # Create a new commit that undoes changes git restore <file> # Restore file to last committed state


8️⃣ Stashing Changes


git stash # Save uncommitted changes for later git stash list # List all stashes git stash pop # Apply latest stash and remove it git stash apply stash@{n} # Apply a specific stash


9️⃣ Rebasing & Interactive Rebase


git rebase <branch> # Rebase current branch onto another git rebase -i HEAD~n # Interactive rebase for last 'n' commits


🔟 Git Tags


git tag <tag_name> # Create a new tag git tag -a <tag_name> -m "Tag message" # Create an annotated tag git push origin <tag_name> # Push tag to remote git tag -d <tag_name> # Delete a local tag git push origin --delete <tag_name> # Delete remote tag


1️⃣1️⃣ Git Hooks


# Hooks are located in .git/hooks directory pre-commit # Runs before commit pre-push # Runs before pushing to remote post-commit # Runs after commit


1️⃣2️⃣ Working with .gitignore & Large Files


echo "node_modules/" >> .gitignore # Ignore files/folders git lfs track "*.mp4" # Track large files


1️⃣3️⃣ Git Workflows & Branching Strategies


# Common branching strategies GitFlow Trunk-Based Development Feature Branching GitHub Flow


Summary & Best Practices

  • Always commit frequently with meaningful messages.
  • Use branches for features and fixes instead of working on main.
  • Regularly pull from remote to stay updated.
  • Use git stash to save changes before switching branches.
  • Avoid git reset --hard unless absolutely necessary.

📌 That’s a complete Git command reference for DevOps! 🚀
Now, you have everything needed to work with Git efficiently.





📚 Top 5 Books That Will Change Your Life!(Top 5 Life-Changing Books) 🚀


1️⃣ Atomic Habits – Build powerful habits and break bad ones!

👉 Get it here

2️⃣ The Psychology of Money – Master your financial mindset!

👉 Get it here

3️⃣ Think and Grow Rich – Unlock the secrets to wealth and success!

👉 Get it here

4️⃣ The Power of Your Subconscious Mind – Train your mind for success!

👉 Get it here

5️⃣ Rich Dad Poor Dad – Learn financial lessons the rich teach their kids!

👉 Get it here

Comments

Popular posts from this blog

Introduction to Terraform – The Future of Infrastructure as Code

  Introduction to Terraform – The Future of Infrastructure as Code In today’s fast-paced DevOps world, managing infrastructure manually is outdated . This is where Terraform comes in—a powerful Infrastructure as Code (IaC) tool that allows you to define, provision, and manage cloud infrastructure efficiently . Whether you're working with AWS, Azure, Google Cloud, or on-premises servers , Terraform provides a declarative, automation-first approach to infrastructure deployment. Shape Your Future with AI & Infinite Knowledge...!! Read In-Depth Tech & Self-Improvement Blogs http://www.skyinfinitetech.com Watch Life-Changing Videos on YouTube https://www.youtube.com/@SkyInfinite-Learning Transform Your Skills, Business & Productivity – Join Us Today! In today’s digital-first world, agility and automation are no longer optional—they’re essential. Companies across the globe are rapidly shifting their operations to the cloud to keep up with the pace of innovatio...

📊 Monitoring & Logging in Kubernetes – Tools like Prometheus, Grafana, and Fluentd

  Monitoring & Logging in Kubernetes – Tools like Prometheus, Grafana, and Fluentd Monitoring and logging are essential for maintaining a healthy and well-performing Kubernetes cluster. In this guide, we’ll cover why monitoring is important, key monitoring tools like Prometheus and Grafana, and logging tools like Fluentd to help you gain visibility into your cluster’s performance and logs. Shape Your Future with AI & Infinite Knowledge...!! Want to Generate Text-to-Voice, Images & Videos? http://www.ai.skyinfinitetech.com Read In-Depth Tech & Self-Improvement Blogs http://www.skyinfinitetech.com Watch Life-Changing Videos on YouTube https://www.youtube.com/@SkyInfinite-Learning Transform Your Skills, Business & Productivity – Join Us Today! 🚀 Introduction In today’s fast-paced cloud-native environment, Kubernetes has emerged as the de-facto container orchestration platform. But deploying and managing applications in Kubernetes is just half the ba...

🔒 Kubernetes Security – RBAC, Network Policies, and Secrets Management

  Kubernetes Security – RBAC, Network Policies, and Secrets Management Security is a critical aspect of managing Kubernetes clusters. In this guide, we'll cover essential security mechanisms like Role-Based Access Control (RBAC) , Network Policies , and Secrets Management to help you secure your Kubernetes environment effectively. Shape Your Future with AI & Infinite Knowledge...!! Want to Generate Text-to-Voice, Images & Videos? http://www.ai.skyinfinitetech.com Read In-Depth Tech & Self-Improvement Blogs http://www.skyinfinitetech.com Watch Life-Changing Videos on YouTube https://www.youtube.com/@SkyInfinite-Learning Transform Your Skills, Business & Productivity – Join Us Today! 🚀 Introduction: Why Kubernetes Security Is Non-Negotiable As Kubernetes becomes the backbone of modern cloud-native infrastructure, security is no longer optional—it’s mission-critical . With multiple moving parts like containers, pods, services, nodes, and more, Kuberne...