Thursday, March 6, 2025

📌 Complete Git Topics for DevOps

 

📌 Complete Git Topics for DevOps



🌍 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! 🔥



4️⃣ Branching and Merging

🔹 Creating and Switching Branches

Command:


git branch <branch_name> # Create a new branch git checkout <branch_name> # Switch to another branch

Best Practice: Use git checkout -b <branch_name> to create and switch to a new branch in one step.



🔹 Merging Branches

Command:


git merge <branch_name>

Best Practice: Always pull the latest changes before merging to avoid conflicts.



🔹 Handling Merge Conflicts

Command:


git status # Identify conflicts git diff # View conflict details

Best Practice: Manually resolve conflicts and commit the changes after resolving.



🔹 Deleting Branches

Command:


git branch -d <branch_name> # Delete a local branch git push origin --delete <branch_name> # Delete a remote branch

Best Practice: Delete unnecessary branches to keep the repository clean.



5️⃣ Working with Remote Repositories

🔹 Connecting with Remote Repositories

Command:


git remote add origin <repository_url>

Best Practice: Use git remote -v to verify the connected remotes.



🔹 Pushing Changes to Remote

Command:


git push origin <branch_name>

Best Practice: Use git push -u origin <branch_name> for the first push to set the upstream branch.



🔹 Pulling Changes from Remote

Command:


git pull origin <branch_name>

Best Practice: Always run git pull --rebase before making changes to avoid merge conflicts.



🔹 Forking a Repository

Best Practice: Forking allows you to create your own copy of a repository and contribute without affecting the original project.



6️⃣ Git Reset, Revert & Restore (Undoing Changes)

🔹 Reset (git reset - soft, mixed, hard)


git reset --soft HEAD~1 # Move HEAD back but keep changes staged git reset --mixed HEAD~1 # Move HEAD back and unstage changes git reset --hard HEAD~1 # Move HEAD back and discard all changes

Best Practice: Be careful with --hard as it permanently deletes changes.



🔹 Revert (git revert)


git revert <commit_hash>

Best Practice: Use git revert instead of reset when working in a shared repository to keep commit history intact.



🔹 Restore (git restore)


git restore <file>

Best Practice: Use git restore to discard changes in specific files without affecting the entire commit.



7️⃣ Stashing Changes

🔹 What is Stashing?

Stashing allows you to save uncommitted changes temporarily without committing them.


🔹 Using git stash


git stash # Save uncommitted changes git stash list # View stashed changes git stash pop # Apply the most recent stash

Best Practice: Use git stash push -m "message" to label stashes for easy identification.





📚 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: https://amzn.to/4ka28CJ

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

👉 Get it here: https://amzn.to/3XiKFOA

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

👉 Buy now: https://amzn.to/4h51HGN

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

👉 Get it here: https://amzn.to/4idNPuR

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

👉 Order here: https://amzn.to/3QzrmNa

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 ...