Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add existing source code folders into Local Git Repository

Tags:

git

git-add

Let's say I have two existing folders that I want to put under Git source control. One is called CurrentProduction and the other CurrentDevelopment. Would the following steps be correct?

  1. Create a new folder called MyProject
  2. git init
  3. Move the CurrentProduction contents to MyProject
  4. git add .
  5. git commit -m 'initial master commit'
  6. git checkout -b develop
  7. Delete all files in MyProject (except for the .git folder of course)
  8. Move the CurrentDevelopment contents to MyProject
  9. git add -A
  10. git commit -m 'initial develop commit'

Or is there a "different" way?

like image 306
Lenard Avatar asked Nov 13 '22 13:11

Lenard


1 Answers

  • Doing it the way you describe will not do any harm.

  • You can move the .git directory into the tree you want to commit instead of moving the tree to the repository.

  • You can use the --work-tree option or GIT_WORK_TREE environment variable to act as if you did that:

    git add --work-tree=CurrentProduction -A; git commit ...
    

    Note that it is not necessary to specify it for commands after add since add copies content into the index, commit uses the index, and the index is in .git.

As a separate issue, note that your procedure will make the develop initial commit a child of the master initial commit. That is probably the right thing for this case; I just want to make sure you're aware it's not symmetric.

like image 67
Kevin Reid Avatar answered Nov 17 '22 04:11

Kevin Reid