"Code, Commit, Conquer: The Ultimate Git Tutorial for DevOps"

"Code, Commit, Conquer: The Ultimate Git Tutorial for DevOps"

πŸ”§ Step 1: Setup Your Cyber Arsenal

πŸ’‘
sudo apt update && sudo apt install git -y

Check installation:

πŸ’‘
git --version
Just to flex. You need to know which version of your sword you’re swinging. πŸ”ͺ

πŸ§‘β€πŸ’» Step 2: Set Git Identity

πŸ’‘
git config --global user.name "Your Name"
git config --global user.email "email@example.com
So Git knows who to blame when things go wrong. This is your digital fingerprint, cyber-ninja. πŸ”

πŸ—‚οΈ Step 3: Initialize the Battlefield

πŸ’‘
cd ~/Python && git init
Boom πŸ’₯ β€” now your folder is under surveillance. Every change is tracked like a suspicious login attempt at 3 a.m.

πŸ”‘ Step 4: Set Up SSH With GitHub

Now go to GitHub β†’ Settings β†’ SSH and GPG Keys and paste it like a pro.

πŸ’‘
cat ~/.ssh/id_rsa.pub

Already done βœ… (You rock). To confirm:

πŸ’‘
You’re testing the connection. GitHub replies like a wise old sensei: "You've successfully authenticated." πŸ§™β€β™‚οΈ

☁️ Step 5: Connect to GitHub Repo

Create a new repo on GitHub β€” leave it empty (no README, no .gitignore).

Then connect:

πŸ’‘
git remote add origin [email protected]:Ashish-butle/Python.git
Adds the GitHub repo as a remote so you can push code into the cloud like magic.

To verify:

πŸ’‘
git remote -v

πŸ’Ύ Step 6: Save and Upload Your Work (So You Don’t Lose It When Your Laptop Explodes)

πŸ’‘
git add .
git commit -m "My glorious Python scripts. Let the world admire."
git branch -M maingit branch -M main
git push -u origin maingit push -u origin main
Stages all your work. Like packing your code into a suitcase before the trip.
Then git commit is your secure checkpoint β€” a snapshot before the code apocalypse. 🧨
Renames the default branch to main (modern times, people), and pushes it to GitHub.

🌿 Step 7: Work on a Separate Branch (So You Don’t Break the Main One)

πŸ’‘
git branch -c sprint1
Creates a new branch for testing. Think of it as a playground where you can mess things up safely.

List all branch

πŸ’‘
git branch -a
Lists all branches, including that one you forgot you made.

πŸ“‹ Step 8: Push Your Changes (Hopefully After They Work)

πŸ’‘
git checkout sprint1

Added some text and files

Tells you what’s changed, because guessing is not a best practice.

πŸ’‘
git status
Tells you what’s changed, because guessing is not a best practice.

Stages, commits, and pushes your changes. This is your β€œHey GitHub, look what I made!” moment.

πŸ’‘
git add .
Stages all your work. Like packing your code into a suitcase before the trip.

Commits (saves) the changes with a message. Make it useful, or your future self will regret it.

πŸ’‘
git commit -m "new changes"
Then git commit is your secure checkpoint β€” a snapshot before the code apocalypse. 🧨

Renames the default branch to main (modern times, people), and pushes it to GitHub.

πŸ’‘
git push origin sprint1

πŸ” Step 9: Merge Branches (Without Causing a Code Meltdown)

πŸ’‘
git switch main

Merges your work from sprint1 into main. Be sure to test first, or your teammates might hunt you down.

πŸ’‘
git merge sprint1

Now we are pushing to the main branch

πŸ’‘
git push origin main

Git status

πŸ’‘
git status

πŸ•°οΈ Step 10: See What Happened (Because Memory is Overrated)

πŸ’‘
git log --oneline

πŸ‘― Step 11: Clone or Update Code (Because Copy-Paste Only Works Locally)

πŸ’‘
git clone git@github.com:Ashish-butle/Python.git

Makes a full copy of the repo on your machine. The legal way to β€œsteal” code.

πŸ” Pulling Updates

πŸ’‘
git pull origin main
Gets the latest updates from GitHub. Do this often, or enjoy merge conflicts.

πŸ› οΈ Step 12: Fix Mistakes (Because Mistakes Will Happen)

Undo local changes: Restores the file to the last committed state. Like Ctrl+Z, but cooler.

πŸ’‘
git restore filename.py

Unstage a file: you accidentally added. We’ve all been there.

πŸ’‘
git reset filename.py

Undoes a bad commit safely by making a new one. Recommended for public repos.

πŸ’‘
git revert <commit id>

Goes back in time and deletes history. Use only if you really mean it β€” no takebacks.

πŸ’‘
git reset --hard <commit id>

πŸš€ Conclusion

Git is your time machine, project manager, and panic button β€” all in one.
Start small, commit often, and remember: git status is your best friend when things go weird.