1

I am trying to get validation on how to go about setting up a git repo from our existing 3 folder structure (dev,beta,prod). I understand the technical/what commands to type part. But how do I go about creating the 3 branches from the 3 folders. Unfortunately these aren't new project we can start fresh with git on, there are lots of files already in play. And the dev folder varies a good bit from the beta/prod folders.

Our idea

  1. Create the repo in the prod folder, making it the 'master' branch.
  2. Then create a branch 'release', this would match master for now (we have no beta testing happening now, so disregarding/deleting the beta folder).
  3. Next create a 'dev' branch.
  4. Delete the files from the folder/dev branch?...
  5. Copy files from the dev folder in?...
  6. Track, stage, commit...?

Steps 4-6 are the concerning part, I don't know if deleting all the files then copying in from the dev folder would be missing anything

In theory this would give us the three branches we could pull/clone from to our local machines. Merging into release and prod from dev would have to be interactive/cherry-picked for a bit, which I think we can manage.

Any advice is greatly appreciated, even if it's a yelling and screaming of 'no wait, not that way!'

undeadDog
  • 21
  • 3
  • What VC is it in now? Is there no migration path from it to git that would let you import the history from it? – Wes Hardaker Apr 16 '14 at 14:02
  • No VC currently, we kept file changes in excel sheets per project. When we needed to push a new feature/version we moved the listed files to beta, tested, moved to prod. Keeping file versions in prod as 'filename.ext_BAC_date'. So keeping history is not a concern. – undeadDog Apr 16 '14 at 14:12

2 Answers2

0

Create a central repository

Start by creating a repository that will hold your branches. For this example I'm just going to use the filesystem but of course in practice this would probably be hosted on a remote server:

$ git init --bare project.git

Add the prod folder

Change to your prod directory and initialize a git repository there:

$ cd prod
$ git init

Create a branch named "prod":

$ git checkout -b prod

Add all your files:

$ git add .
$ git commit -m 'added prod files'

And the remote:

$ git remote add origin /path/to/project.git

And push:

$ git push origin prod

Add the dev folder

Change to your dev folder and initialize a git repository there:

$ cd dev
$ git init

Add the remote repository:

$ git remote add origin /path/to/project.git

Create a new dev branch:

$ git checkout -b dev 

Add all your files:

$ git add .
$ git commit -m 'added dev files'

And push:

$ git push origin dev

Add the beta folder

Repeat the same process for your beta folder:

$ cd beta
$ git init
$ git remote add origin /path/to/project.git
$ git checkout -b beta
$ git add .
$ git commit -m 'added beta files'
$ git push origin beta

Clone your main repository

Create a working copy from your bare repository:

$ git clone -b prod /path/to/project.git
$ cd project

The -b prod here causes git to checkout the prod branch. Look at the available branches:

$ git branch -a
* prod
  remotes/origin/beta
  remotes/origin/dev
  remotes/origin/prod

And now you're all set.

larsks
  • 277,717
  • 41
  • 399
  • 399
0

You have to consider the alternative that the folders you describe map better onto separate repositories rather than branches in a single repository, especially if the dev folder is significantly different, as you state, to the other ones.

You can create a repo for each of the branches, add them as remotes all around in every other repo, and the merge into release and prod from the dev repo (say a remote dev/master branch) can be a cherry-pick still. Subsequently in the future you can take this further and treat all the repos as sub-modules in an uber repo.


For your question, in the one repo that includes everything, you seem to be concerned with importing files in a folder into a branch. You can proceed as follows:

  1. Create the branch

    master$ git co -b devb

  2. Copy the folder over

    devb$ cp -r /path/to/external/dev dev

  3. Add the folder and the files recursively to git

    devb$ git add dev

  4. Commit the result

    devb$ git commit -m "initial dev commit"

mockinterface
  • 14,452
  • 5
  • 28
  • 49
  • What would be some of the benefits of keeping separate repos for dev and prod instead of branching. I am seeing it as a six in one basket/half dozen in the other basket. We'll still have to cherry-pick out merges. – undeadDog Apr 16 '14 at 17:25
  • @undeadDog See http://stackoverflow.com/questions/11873527/benefits-of-using-git-branches-vs-multiple-repositories – mockinterface Apr 16 '14 at 21:42