Git Fundamentals for Developers: Essential Commands and Best Practices

Over the past two days, I spent time learning Git and GitHub in detail with hands-on practice. Version control is a fundamental skill for Developers, DevOps Engineers, and SREs because it helps track code changes and enables smooth collaboration. Here are some important Git commands that every developer should know 👇 📦 Repository Setup 🔹 git init → Initialize a new Git repository 🔹 git clone <repo-url> → Clone a repository from GitHub ------------------------------------------------------------------- 📂 Tracking Changes 🔹 git status → Check the current status of files 🔹 git add <file> → Add specific file to staging area 🔹 git add . → Add all files to staging ------------------------------------------------------------------- 💾 Saving Changes 🔹 git commit -m "message" → Save changes with a commit message 🔹 git log → View commit history --------------------------------------------------------------------- 🌿 Branch Management 🔹 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 and switch branch -------------------------------------------------------------------------- 🔀 Merging & Collaboration 🔹 git merge <branch> → Merge branches 🔹 git pull → Fetch and merge changes from remote repo 🔹 git push → Push local commits to GitHub ----------------------------------------------------------------------- 🔄 Undo & Recovery Commands 🔹 git reset → Undo commits and move HEAD 🔹 git reset --soft HEAD~1 → Undo commit but keep changes staged 🔹 git reset --hard HEAD~1 → Remove commit and changes 🔹 git revert <commit-id> → Safely reverse a commit --------------------------------------------------------------------- 🌐 Remote Repository Management 🔹 git remote add origin <repo-url> 🔹 git remote -v -------------------------------------------------------------- 🧪 Hands-on Practice I Performed: ✅ Created local repositories ✅ Managed branches and commits ✅ Practiced git reset and git revert ✅ Connected local repository with GitHub ✅ Pushed and pulled code from remote repositories #DevOps 🚀 #Git #GitHub #VersionControl #TechLearning #HandsOnPractice #ContinuousLearning #DevOpsJourney

  • logo, company name

To view or add a comment, sign in

Explore content categories