Friday, March 7, 2025

📌 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

No comments:

Post a Comment

Terraform State Deep Dive: Why it's Crucial and How to Manage It

Terraform State Deep Dive: Why it's Crucial and How to Manage It ...