⚙️ Git & GitHub for DevOps – Part 2: Master Forks, Remotes, Rebasing & Recovery - Day 6
Level up your DevOps Git skills with upstream workflows, remotes, rebasing, stash tricks, and real-time recovery scenarios every engineer must master.

DevOps/Cloud Engineer focused on building, automating, and scaling cloud native systems. I write about Linux, CI/CD pipelines, Docker, Terraform, Kubernetes, and AWS, sharing practical insights from real-world DevOps workflows.
A. Clone, Fork & Upstream Workflow
Problem: I cloned a repo but need to contribute to an open-source project, how do I sync with the original repo?
Action: Use fork → clone → add upstream → sync regularly.
Commands:
# Clone your fork
git clone https://github.com/yourname/project.git
# Add upstream (original repo)
git remote add upstream https://github.com/original/project.git
# Fetch latest changes
git fetch upstream
# Sync your local main
git checkout main
git merge upstream/main

When committing the changes, Git may prompt you to set your account identity. Be careful not to use the --global flag, because doing so will apply your name and email to respective repository on the system. This means anyone committing from that machine would appear to be you. Instead, remove the --global flag and set your identity (username and email) only for the current repository, as shown below:


Key Takeaway: Always keep your fork updated to avoid huge conflicts when raising PRs.
B. Handling Remotes Properly
Problem: My repo has multiple remotes, how do I fix or rename them?
Action: Use remote commands to view, rename, remove safely.
Commands: git remote -v
git remote rename origin old-origin
git remote remove upstream
git fetch origin
Note: After running the command git fetch origin, we received an error saying that ‘origin’ does not appear, because we had renamed it in a previous command

Note: Again rename the origin and pull the origin main
git remote rename old-origin origin
git pull origin main (If any issues occur while rebasing, first commit the changes as shown below)
git pull --rebase origin main

Key Takeaway: Clean remote configuration makes collaboration smooth and avoids wrong pushes.
C. Commit Perfection Techniques
Problem 1: I made a typo in the last commit message.
Action: git log -1
git commit –amend -m <new message>

Note: git log -1 is used to check the last commit message
Problem 2: I want to completely undo a commit without deleting the code.
Action: git log --oneline
git revert <commit-id>


Problem 3: I want to move HEAD but keep my changes staged.
Action: git reset --soft HEAD~1

Key Takeaway: Use amend/reset/revert responsibly, they shape clean, production-ready commit history.
D. Ignoring Files Properly
Problem: Node modules, logs, and temporary files are showing up in Git!
Action: Use .gitignore + global ignore.
Commands:
echo "node_modules/" >> .gitignore

git config --global core.excludesfile ~/.gitignore_global

Note: Some files, like OS temp files or editor configs, should never be committed in any repo. For that, use a global ignore file
Key Takeaway: A good .gitignore protects your repo from unnecessary junk.
E. Stashing Your Temporary Storage
Problem: I need to switch branches but my changes aren’t ready to commit!
Action: Use stash to save and restore work.
Commands: git stash
git stash list

git stash apply stash@{0}
git stash drop stash@{0}

DevOps Case: Service down → hotfix branch → stash your WIP → switch → fix → return.
Key Takeaway: Stashing keeps your work safe when context switching.
F. Practical DevOps Scenarios
Scenario A: My branch is behind main, how do I update safely?
Action: Rebase or merge.
Commands: git checkout feature
git fetch origin
git rebase origin/main

Key Takeaway: Rebase = cleaner history, Merge = safer for beginners.
Scenario B: I committed secrets accidentally!
Action: Use reset + force push (only if allowed).
Commands:
git reset --soft HEAD~1
# remove secrets
git commit -m "Remove Secrets"
git push -f origin feature/login-page


Key Takeaway: Rotate the secret immediately. Never commit credentials.
Scenario C: My PR shows too many commits!
Action: Fix with interactive rebase
Commands: git rebase -i origin/main


Key Takeaway: Squash commits before PR → Clean & professional.
Scenario D: I pushed the wrong code to main!
Action: Rollback using revert.
Commands: git log / git log -1 / git log -2
git revert <bad-commit>
git push origin main


Takeaway: Revert is production-safe. Avoid force pushing on protected branches.
G. GitHub Features That Matter in DevOps
Problem: How do teams avoid bad merges and maintain quality?
Action: Use GitHub governance tools:
✔ Issues
✔ Labels
✔ Project boards
✔ Branch protection rules
✔ Required PR reviews
✔ Status checks
✔ GitHub Actions (CI/CD)
Takeaway: Governance ≠ restriction
It ensures safe, reliable, predictable deployments.
Topic’s Covered Today:
Clone, Fork & Upstream Workflow
Handling Remotes Properly
Commit Perfection Techniques
Ignoring Files Properly
Stashing Your Temporary Storage
Practical DevOps Scenarios
GitHub Features That Matter in DevOps