Skip to content

Instantly share code, notes, and snippets.

@Hansimov
Last active November 10, 2023 17:06
Show Gist options
  • Save Hansimov/60bd27343ff7484fbb3a8d7fa28fbfef to your computer and use it in GitHub Desktop.
Save Hansimov/60bd27343ff7484fbb3a8d7fa28fbfef to your computer and use it in GitHub Desktop.
Separate subfolder in current Git repo to a new repo
  1. Create a new folder where would place the new repo
  2. git clone the original repo under this folder
  3. Download git-filter-repo from here: (Do not chagne its extension)
  4. cd the cloned repo root folder, and run following: python git-filter-repo --path <directory_to_separate_to_new_repo> --force
  5. Copy follwing files to root path of the new folder created in step 1:
    • Remaining files under <directory_to_separate_to_new_repo>
    • .git directory in original repo root folder
    • Run git status in the new folder root, to check the git status
    • Run git rev-list --count main to check the commits count of separated directory
  6. git add ., and commit the change as a re-organizing of file structure
  7. Create new repo in Github, and get its url, then run:
    git remote add origin https://github.com/<owner>/<new_repo>.git
    git remote -v
    git push -u origin main
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment