DEV Community

Cover image for How do you use git rebase? Let's go through one use case

How do you use git rebase? Let's go through one use case

Schalk Neethling on April 23, 2024

I have been making these short (1 to 5-minute) videos covering a specific topic that I use daily or frequently. I have been posting them to my YouT...
Collapse
 
oculus42 profile image
Samuel Rouse

Thanks for the article! I am a fan of git rebase (I used it twice already today!) and it's good to see more people talking about it. People can be apprehensive about these git operations, but they are very powerful.

I especially appreciate the insight of fixup vs squash!

In a case like the one you described, I often go with git commit --amend for these small edits, but I can definitely see the benefit to making the individual commits and having the option to make changes afterwards.

Collapse
 
schalkneethling profile image
Schalk Neethling

Nice! Yes, I use --amend as well every now and again. There is a lot more to Git that I do not yet know, so I will most likely be making more of these as I learn new and practical uses of the many commands.

In general, I would also love to have a deeper understanding of how Git works.

Collapse
 
ccoveille profile image
Christophe Colombier • Edited

I'm an advanced git users, I use git rebase interactive daily when not hourly 😅

I appreciate you made a post about it. So people will get familiar with its usage.

Reading your post inspired me in writing an article I wanted to write for ages. So thank you.

Here it is

Collapse
 
schalkneethling profile image
Schalk Neethling

Amazing! That makes my day. I am glad I could inspire you to write the above. Thanks for sharing!

Collapse
 
fabrikapp profile image
Fabrikapp

Always useful, thanks for the tips !

Collapse
 
schalkneethling profile image
Schalk Neethling

You are very welcome! Would you be keen to see more of these? Anything specific you would like me to cover?

Collapse
 
fabrikapp profile image
Fabrikapp

Yes sure, even after 15 years of development git commands still seems odd to me. I was wondering about modifying history in remote repository while using git reset, in a "security" point of view.

From your article, it seems to imply that while using git rebase, it will change the remote history as well, as you need to force it.

  • Would the old history still be visible somewhere ? Or is it safe to conclude that old history will not be visible ?

Let's say -a good friend- accidently committed an ENV key and pushed a commit, is there a way to reorganize history to completely remove it from .git history or could it be recover by digging or recovering traces ?

Thread Thread
 
schalkneethling profile image
Schalk Neethling

That is a good question. My knee-jerk reaction would be, if you changed history this way and force-pushed, that history is lost, but... I am also thinking mainly the commit history, not the underlying changes so there might very well still be a way to drudge that up. This is why it is important to use things like GitHub's push protection. github.blog/2023-05-09-push-protec...

I will do some digging, as "a friend" has also done this before. We had to rotate the keys so, that is why my general thinking is that that key and the related changes are still in history.

Thread Thread
 
fabrikapp profile image
Fabrikapp

Haha, thanks for your reply ! We all got that one friend ^^
Yes, safe guards can be usefull, I'll add Github Push Protection, or well the Bitbucket equivalent, if it's available !

Collapse
 
mikec711g profile image
Michael Casile

You do a great job including the Why you would do this along with the What you can do. Also why this might not be a good idea in some situations. Thanks for sharing your wisdom

Collapse
 
schalkneethling profile image
Schalk Neethling

Thank you for taking the time to write this thoughtful comment. I am glad you found value in this. 🙌 or old school o/\o

Collapse
 
agesset profile image
Eag

Nice tip✨✨! It will be very fan if we can have more tips about how to handle correctly git.

Collapse
 
schalkneethling profile image
Schalk Neethling

Thank you for your feedback. There is more coming!

Collapse
 
schalkneethling profile image
Schalk Neethling

It sounds like the general consensus is, "We want more of this!" 😃

Well, alrighty then ;p

Collapse
 
osonwa profile image
Osonwa

Nice tip, learnt something new

Collapse
 
schalkneethling profile image
Schalk Neethling

That is great to hear!