Question

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?

Was it helpful?

Solution

  • 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.

OTHER TIPS

It is a good way.

The only possible issue if you look at the history of the develop branch with git log you will have the current production project state as last commit (the one with 'initial master commit'). Which semantically not fully correct.

If that bothers you can make first an initial empty commit which servers as a common base for the two branches:

git init .
git commit --allow-empty -m "initial commit"
# add CurrentProduction content
git add .
git commit -m "initial master commit"

# checkout at the empty commit
git checkout -b develop HEAD^

# no need to delete any files!
# working tree is empty
# add CurrentDevelopment  content
git add .
git commit -m "initial develop commit"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top