• Arsecroft
    link
    fedilink
    154
    edit-2
    9 days ago

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

    • Lucy :3
      link
      fedilink
      7
      edit-2
      8 days ago

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

        • Lucy :3
          link
          fedilink
          18 days ago

          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?

          • @stembolts@programming.dev
            link
            fedilink
            8
            edit-2
            8 days ago

            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.

            • @Hoimo@ani.social
              link
              fedilink
              38 days ago

              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.

              • @stembolts@programming.dev
                link
                fedilink
                2
                edit-2
                8 days 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.

              • @Jayjader@jlai.lu
                link
                fedilink
                26 days 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.

              • Ethan
                link
                fedilink
                English
                17 days ago

                You can also just tell GitHub to not do that.

          • @dev_null@lemmy.ml
            link
            fedilink
            38 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@lemmy.world
        link
        fedilink
        English
        59 days ago

        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)

        • Lucy :3
          link
          fedilink
          38 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.