Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to duplicate directory in git, tracking new files?

Tags:

git

directory

Is there a simple way to create a copy of a folder in a local repository, keeping track of exactly the same files (do not care about commit history, or untracked files)?

The folder contains a hierarchy of both tracked and untracked (but not ignored) files and directories. I basically want to recursively replicate the tracked structure. Is there a way other than copying everything, and then manually adding only the relevant files (there are a lot of them)?

like image 329
Yuri Feldman Avatar asked Sep 06 '25 11:09

Yuri Feldman


1 Answers

If you don't care about the history, you could just copy the directory and then git add it:

$ cp -R old_dir new_dir

$ git add new_dir

$ git commit -m "first revision of new_dir's copied files"
like image 177
Mureinik Avatar answered Sep 09 '25 10:09

Mureinik