Christopher Chiche
Christopher Chiche

Reputation: 15335

Create branches from separate directories

I have the following directory structure:

Application/V1
Application/V2
Application/V3

None of these directories are Git repositories. I can also add that each of these directories contain exactly the same files (but the code in these files obviously changes)

From that, I would like to create a new git repository with 3 branches being V1, V2 and V3.

I was thinking of creating a new directory which would contain a .git file in which I could checkout the 3 git branches (i.e a real Git repo). So, my question is: even if this manipulation is not git-friendly at all, how can I achieve this in an elegant way?

Upvotes: 0

Views: 82

Answers (1)

Christopher Chiche
Christopher Chiche

Reputation: 15335

Here is the working solution I came with (but I am still looking for a more elegant one if possible)

mkdir gitDir
cd gitDir
git init

cp -r ../V1/*
git add * 
git commit -am "Init Commit for V1"
git branch -m V1

git checkout -b V2
rm -rf *
cp -r ../V2/*
git commit -am "Commit for V2"

git checkout -b V3
rm -rf *
cp -r ../V3/*
git commit -am "Commit for V3"

Upvotes: 1

Related Questions