DEV Community

Discussion on: How And When To Use Git Reset

Collapse
 
jmfayard profile image
Jean-Michel 🕵🏻‍♂️ Fayard • Edited

My best use case for git reset is when I want to update my pull request, merge master and clean up the git history

  • git fetch and git merge origin/master
  • Resolve conflicts and commit
  • git reset --soft origin/master same exact code in the repository but clean git history
  • commit and git push --force
Collapse
 
char_bone profile image
Charlotte

Interesting use case. So you're merging all of your pull requests commits into one commit. I can see that this makes the history cleaner. I personally like to keep that commit history in projects, especially for a big merge. It makes it easier to step back to a more specific point in the future after the merge. I can definitely see the benefits though :)

Collapse
 
jmfayard profile image
Jean-Michel 🕵🏻‍♂️ Fayard

On GitHub you can do the same thing with merge and squash the commits.
The history in master is kept clean but you have a link to the pull request to see the details

Thread Thread
 
char_bone profile image
Charlotte

Yeah it definitely makes sense, especially if you do lots of tiny commits then you would clutter the main branch :) I guess there is a balancing act though as to leaving enough commits to be able to cherry pick certain functionality in future (rather than looking at a pull request and manually doing things)