Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9268503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:49:56+00:00 2026-06-18T14:49:56+00:00

I currently have a big git repository that contains many projects, each one in

  • 0

I currently have a big git repository that contains many projects, each one in its own subdirectory. I need to split it into individual repositories, each project in its own repo.

I tried git filter-branch --prune-empty --subdirectory-filter PROJECT master

However, many project directories went through several renames in their lives, and git filter-branch does not follow renames, so effectively the extracted repo does not have any history prior to the last rename.

How can I effectively extract a subdirectory from one big git repo, and follow all that directory’s renames back into the past?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:49:57+00:00Added an answer on June 18, 2026 at 2:49 pm

    Thanks to @Chronial, I was able to cook a script to massage my git repo according to my needs:

    git filter-branch --prune-empty --index-filter '
        # Delete files which are NOT needed
        git ls-files -z | egrep -zv  "^(NAME1|NAME2|NAME3)" | 
            xargs -0 -r git rm --cached -q             
        # Move files to root directory
        git ls-files -s | sed -e "s-\t\(NAME1\|NAME2\|NAME3\)/-\t-" |
            GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
            git update-index --index-info &&
            ( test ! -f "$GIT_INDEX_FILE.new" \
                || mv -f "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE" )
    '
    

    Basically what this does is this:

    1. Deletes all files outside of the three directories NAME1, NAME2 or NAME3 that I need (one project was renamed NAME1 -> NAME2 -> NAME3 during its lifetime).

    2. Moves everything inside these three directories to the root of the repository.

    3. I needed to test if “$GIT_INDEX_FILE.new” exists since import of svn into git creates commits without any files (directory-only commits). Needed only if the repo was created with ‘git svn clone’ initially.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have one project that currently contains multiple packages. These packages make up
I'm converting a big SVN repository into multiple git repositories (one for each project).
I now have a big honking, bloated, Git repository consuming mucho disk space on
I currently have a Java ByteBuffer that already has the data in Big Endian
We currently have a big Maven 2 project that is rather a collection of
I currently have a big big directory filled with many sub-directories with identically named
I have a big problem with git-svn: I need to just push my git
We currently have a big project that consists of the following layers: MS SQL
I currently have the following code that replaces a big image when a thumbnail
I have big records to copy values from table B to table A. Currently

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.