CodeNewbie Community 🌱

Discussion on: #CNC2021 "Write More" Mission 2 [pt. I] Submission Thread

 
gaurang847 profile image
Gaurang

It's my personal safety measure when dealing with these kinds of things.
When you're trying to solve a Git issue, you often need to revert certain commits, reapply them, merge and rebase branches, etc. right?
You're essentially re-writing (Git) history.
If you're not careful, you could lose important parts of your code. And if you push it to the origin without realizing what you've done, you're in developer hell. RIP.

To avoid that, this is what I generally do. If I feel unclear about how to solve a problem, I clone the repo again in another directory and checkout the branches that I'm gonna touch on.
This is the backup clone.

If things go south and I lose some code. Or I somehow mess up the history more than it already was. I can just scrape the existing local repo and start using the backup clone.
Now if I'm having one of my worse days. And I force-push my changes to the origin without realizing that I've made a blunder.
I can just go to my backup clone and run git push --force origin master.

It's basically like a save-point before the boss battle.

Thread Thread
 
lyqht profile image
Estee Tey

ohh, now i understand what you mean by "backup clone"! I also like your analogy of "save-point before the boss battle", you could include that in your article :P

I do that sometimes as well when it comes to complicated merge/rebase xD

A trick that my friend taught me recently was to just remove the branch that has problems entirely from your local machine and then git pull to get that branch completely fresh from remote - but of course this trick only applies if the problem is only for that branch and that you don't need any local changes on that anymore.

Looking forward to your cherry picking article! Haven't tried it before.

Thread Thread
 
gaurang847 profile image
Gaurang

Oh! Imma include the whole comment in my post! 😆

A trick that my friend taught me recently was to just remove the branch that has problems entirely from your local machine and then git pull to get that branch completely fresh from remote - but of course this trick only applies if the problem is only for that branch and that you don't need any local changes on that anymore.

Ah yes! That's a good one.

Looking forward to your cherry-picking article! Haven't tried it before.

Thanks, man! 😌
The deployment practice at my work is such that I often have to cherry-pick commits for a release 😅
I hope you'll like the article. Would you be interested to review a more mature draft once it's ready?

Thread Thread
 
lyqht profile image
Estee Tey

sure of course! 😄