• stembolts@programming.dev
    link
    fedilink
    arrow-up
    8
    ·
    edit-2
    4 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
      arrow-up
      3
      ·
      4 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.

      • Jayjader@jlai.lu
        link
        fedilink
        arrow-up
        2
        ·
        3 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.

      • stembolts@programming.dev
        link
        fedilink
        arrow-up
        2
        ·
        edit-2
        4 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.