DEV Community

Discussion on: What dev topic do you think you should understand, but don't?

recursivefaults profile image
Ryan Latta

While its true that git kind of demands you understand it on some level before it plays nice with you there are basically 3 things that will destroy work (And even then a wizard can perform a ritual to bring it back).

  1. push -f If you get asked to do that its because you've done something to re-write history in a way that is inconsistent. Stop there.

  2. rebase rebase is a command that allows you to re-write history. You'll see lots of advice to use it to clean up commits, or to do a pull --rebase. Either way, history is re-written. pull --rebase is actually pretty benign and can be used most of the time. When you get a conflict though, it can get messy as you'll be re-writing your already finished commits.

  3. reset --hard <commit> This little one basically will have you go back in time. Harmless when you are using it on a commit that you haven't pushed. Uncool when you do it to commits that have already been pushed/pulled. It'll likely trigger a prompt to do a push -f

Git does take time to understand and get comfortable with. It supports a variety of workflows and styles. That flexibility often means its pretty confusing to get used to. For the overwhelming majority of use cases you'll rarely need any of the commands I mentioned.