this post was submitted on 21 Mar 2025
723 points (98.7% liked)

Programmer Humor

21776 readers
1674 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 148 points 2 days ago* (last edited 2 days ago) (2 children)

this guy would have force pushed onto main about 10 mins after this if he did have git

[–] pivot_root 34 points 2 days ago (1 children)

And then lost the reflog by rm -rfing the project and cloning it again.

[–] [email protected] 2 points 2 days ago

God bless DCVS.

[–] [email protected] 6 points 2 days ago* (last edited 2 days ago) (2 children)

Tbf you have to do that for the first push, if a Readme file was autogenerated

[–] [email protected] 5 points 2 days ago (1 children)

You don't if you just clone the repo you created.

[–] [email protected] 1 points 2 days ago (3 children)

Huh? I'm talking about existing code being in a dir, then initting a git repo there, creating a pendant on your hoster of choice and then pushing it there. Wouldn't cloning the repo from step 3 to the code from step 1 overwrite the contents there?

[–] [email protected] 4 points 2 days ago* (last edited 2 days ago) (1 children)

There are multiple solutions to this without using --force.

Move the files, clone, unmove the files, commit, push being the most straightforward that I can summon at this time.. but I've solved this dozens of times and have never use --force.

[–] [email protected] 2 points 1 day ago (3 children)

If your remote is completely empty and has no commits, you can just push normally. If it has an auto-generated "initial commit" (pretty sure Github does something like that), you could force push, or merge your local branch into the remote branch and push normally. I think cloning the repo and copying the contents of your local repo into it is the worst option: you'll lose all local commits.

[–] [email protected] 1 points 4 hours ago

If it's a single, generated, "initial" commit that I actually want to keep (say, for ex I used the forge to generate a license file) then I would often rebase on top of it. Quick and doesn't get rid of anything.

[–] [email protected] 1 points 19 hours ago

You can also just tell GitHub to not do that.

[–] [email protected] 1 points 1 day ago* (last edited 1 day ago)

True, in the situation with a local history maybe it's worthwhile to --force to nuke an empty remote. In that case it is practical to do so. I just typically like to find non-force options.

[–] [email protected] 2 points 2 days ago

Yeah, I was thinking of a new repo with no existing code.

In your case you'd want to uncheck the creation of a readme so the hosted repo is empty and can be pushed to without having to overwrite (force) anything.

[–] computergeek125 5 points 2 days ago (1 children)

Does that still happen if you use the merge unrelated histories option? (Been a minute since I last had to use that option in git)

[–] [email protected] 2 points 2 days ago

Never have heard of that, but in the case of you also having a Readme that will be even more complicated, I imagine. So just adding -f is the easier option.