简体   繁体   中英

How to import an existing project to Git?

I started a coding project, which has expanded in size and I want to use Git for version control. If that matters, the project is combination of web infrastructure written in HTML/CSS/PHP and server infrastructure written in C.

I currently work in the following way: I perform changes in my development directory: /var/www/dev . Once I am satisfied I manually move the changed files to the live directory: /var/www/stable . Both stable and dev are currently the same, but are web-accessible through different domains: foo.com and dev.foo.com

I have learned the basics of Git and I am familiar with the commands, but I can`t figure out how to migrate the project, although reading several questions on Stackoverflow. I want to maintain a dev version accessible at dev.foo.com. Should I do it that way:

  1. Open /var/www/master and create the repo with: git init , git add . and git commit .
  2. Open /var/www/dev and pull the repo with: git pull file:////var/www/stable .

Once that is done, I should be able to work in my dev environment and have branches in the dev repo, but how will I push the changes to the stable version? Is there a better way to organize that process?

You may create a bare repo that you push your work to and fetch changes to the stable directory. Make a clone in the stable directory and another clone where you do the actual work.

In a directory where you keep the bare repo

git init --bare

In the stable directory

git init
git add .
git commit -m "first commit"
git remote add origin <path to bare repo>
git push origin master

Create a clone where you do the work

git clone <path to bare repo> dev
cd dev
git fetch
...do some work ...
git add .
git commit -m "fix for...."
git push origin master

When you are sattisfied with the your work, go back to the stable directory

git pull origin

This is one way of doing this, you may need to change this workflow so suite your needs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM