First things first:
Is there a way this can be achieved by moving/copying the folders and creating a repo on the fly?
No. git
is not cvs
. The structure of git
fundamentally doesn't support what you're asking for. Commits - the objects that trace out the history - are made up of snapshots of the entire project. Nowhere is there an object or collection of objects that represents "exactly the history of the f1
subdirectory". There is enough information that you can produce such objects, but to do so you need a clone (or direct access to the origin).
So then to the comments, when you state reasons not to clone:
There are 2 reasons I do not want to clone: 1. It creates a repo for only one branch. 2. We have many huge repos, and I want to get rid of the cloning overhead
Reason 1 is incorrect. When you clone you copy all branches by default. Even if you've set up a configuration that doesn't default to copying everything, you still can copy everything.
Reason 2 is a nice thought, but you can't do the level of manipulation required to split the repo (including history) with anything less than a full copy of the repo. So if you can log onto the server and the repo is accessible on the filesystem, you can do the work there; but otherwise, you have to clone it. Do it once, split the repo up, and you'll never have to do it again.
Lastly
Also, when the new repo is created, I want to see all the live branches and commit history
After properly cloning the repo, you can use git filter-branch --subdirectory-filter f1 -- all
to rewrite the history and produce your first "new" repo.
Then you clone that.
Then you go back and restore all the branches to their previous state using the backup refs stored under originals/*
Then you repeat for each other directory you want to break out.