I’m thinking on writing some tutorial on de-sloppifying some open-source projects, with I’m likely ending up at least starting some of them.

  • bignose@programming.dev
    link
    fedilink
    English
    arrow-up
    6
    ·
    edit-2
    23 days ago

    It may depend where the project is and what you want to bring with you.

    If you’re asking solely about the Git repository: you need to find exactly which commit is the latest one you want to bring, and specify that commit identifier (the hash of that commit) as the “starting point” when you create a new branch.

    git branch […] <branch-name> [<start-point>]

    https://git-scm.com/docs/git-branch

    So, clone the repository locally however you need to do that. Then, in your local repository, modify what the branches point to:

    e.g. If you determined the latest commit you want to bring, has commit identifier “deadbeefbad1dea”, you can create the branch named “before-the-slop”:

    git branch before-the-slop deadbeefbad1dea

    Now the new branch “before-the-slop” has all the commits up to that, and no further. That’s what you’ll base your fork on.

    git branch before-the-slop

    git rev-parse HEAD # → deadbeefbad1dea

    Then rename the old “main” or whatever branch, to something like “sloppified-project-main” that gets it out of the way; rename your “before-the-slop” branch to “main”; and set “main” as the default branch in your repository.

    git branch --move main sloppified-project-main

    git branch --move before-the-slop main

    git config set --local init.defaultBranch main

    Some time later, when you’ve confirmed your repository is how you like it, delete the “sloppified-project-main” branch:

    git branch --delete sloppified-project-main

    and breathe easy.