How can I create a new branch in git from an existing file tree?

I want to add an existing file tree to the git repository as a new branch (I cannot just copy the existing tree to the git tree, since the existing tree is being versioned under a different VCS, and I'm trying to synchronize them).

Is it possible?

EDIT . Will a new git repository be created, connected to an existing remote repository, and then moving the resulting .git folder? It seems really hacky, but if this is the way to do it ...

+1
git version-control
Dec 15 '09 at 17:42
source share
5 answers

You can use the --work-tree=<path> option for git to add files from another directory, for example:

 git --work-tree=/path/to/file add . 
+1
Dec 16 '09 at 19:18
source share

You can

  • create a new branch ( git checkout -b aNewBranch )
  • copy tree
  • add it ( git add path/to/new/tree )
  • and commit

But future synchronization between this new tree under git, and the other in another VCS should be manual: i.e. using the comparison tool to compare two trees and update / add / delete the corresponding files between the two directories.




If you must save the tree where it is (in VCS), you can:

  • see Charles Bailey and git add answer by contacting another git
  • or just git init in your other VCS tree
    • then you can consider git repo as a submodule (less simple, but allows you to link in your git repo the exact link to the VCS tree)
0
Dec 15 '09 at 17:50
source share

I moved the .git folder before and while hackish it worked.

My reason for this was to work with TFS as a โ€œrealโ€ VCS, but using git on my own machine - the TFS branches are actually just copies, so when I was working in the TFS branch, I just checked the branch in git, then moved the .git folder to the TFS root branch.

0
Dec 15 '09 at 18:29
source share

which vcs do you use? I would look around to see if there is an importer from your VCS to Git.

Then just switch to the new branch ( git checkout -b import-branch ) and run the importer.

0
Dec 15 '09 at 18:33
source share

The easiest way to do this is to create a branch based on where you need to add new files, clear the index, and add new files from where they are currently located.

eg.

 git checkout -b newbranch [<option starting sha1>] git rm -r --cached -- . cd /other/tree git --git-dir=/first/tree/.git add . 

Once you do this, you probably want to reset the work tree to its original location.

 cd /first/tree git checkout -- . 
0
Dec 15 '09 at 18:36
source share



All Articles