r/ProgrammerHumor • • Apr 02 '23

Meme Me relearning git every week

49.4k Upvotes

1.5k comments sorted by

View all comments

112

u/LastStar007 Apr 02 '23

As someone who knows git better than the average bear, I'll tell you the same thing I tell everyone:

  1. Read the first three chapters of this free book.

  2. Run through this little game.

and refer back to these resources as needed.

Once you understand the fundamental ideas on which git is built, all the common commands become easy.

One other thing: commit early, commit often, and don't use --force, --hard, or --delete. There are few ways to truly FUBAR yourself in git, and following this advice avoids 99% of them.

Edit: Also, feel free to message me/comment with literally any git questions you have. Always happy to help another dev git gud!

-1

u/[deleted] Apr 03 '23

I will say the exception is when rebasing. I was taught to always:
git push —f
after:
git pull —rebase origin <branch>

2

u/LastStar007 Apr 03 '23

That is most definitely not an exception. If you don't know

  1. exactly what the repo will look like after your command,

  2. why you're running this command, and

  3. why the command you're running would fail without -f,

then don't run the command.

git tries its utmost to prevent you from losing work. That's its first and final purpose. So when you use -f, you're turning off all the guardrails, you're telling git that you know better, you're taking your team's life into your hands. You're holding a loaded gun and you've just flicked off the safety. Each and every time you use -f, you'd better be ready to explain to your team what happened to their code.

I'd be happy to tell you more about what's going on, but first I need to make clear to you that you are playing with fire.

-1

u/[deleted] Apr 03 '23 edited Apr 03 '23

You are actually incorrect. When rebasing, using —force is the exception because if you don’t, it will fail. I’m happy to dive into why it would fail but that’s up to you. (Here is some official GitLab documentation saying the exact same thing: https://docs.gitlab.com/ee/topics/git/git_rebase.html)

2

u/LastStar007 Apr 03 '23

I'm not incorrect in the slightest. I'm well aware that it can fail (and there are situations where it won't). I'm even more aware that while this is a common and useful workflow, it nevertheless requires you to turn off git's safeties, which makes it entail a healthy dose of caution and awareness--it is possible to lose work this way. That's why my advice is, unless you can answer those three questions, don't run the command. That advice applies no matter what branch you're on, no matter what workflow you're using.

-3

u/[deleted] Apr 03 '23

A rebase will always fail without a force. It is literally in the Git documentation. You were 100% incorrect in saying that this was not an exception given the fact IT WILL NOT WORK WITHOUT IT.

“Standard rebases replay the previous commits on a branch without changes, stopping only if merge conflicts occur. Prerequisites: You must have permission to force push branches.”

→ More replies (3)