Skip to content

Latest commit

 

History

History
121 lines (85 loc) · 4.72 KB

new_project_git.rst

File metadata and controls

121 lines (85 loc) · 4.72 KB
.. index::
   single: Workflow; Git

How to Create and store a Symfony2 Project in Git

Tip

Though this entry is specifically about Git, the same generic principles will apply if you're storing your project in Subversion.

Once you've read through :doc:`/book/page_creation` and become familiar with using Symfony, you'll no-doubt be ready to start your own project. In this cookbook article, you'll learn the best way to start a new Symfony2 project that's stored using the Git source control management system.

Initial Project Setup

To get started, you'll need to download Symfony and initialize your local git repository:

  1. Download the Symfony2 Standard Edition using Composer:

    $ php composer.phar create-project symfony/framework-standard-edition path/ ~2.3

    Composer will now download the Standard Distribution along with all of the required vendor libraries. For more information about downloading Symfony using Composer, see Installing Symfony using Composer.

  2. Initialize your Git repository:

    $ git init
  3. Add all of the initial files to Git:

    $ git add .

    Tip

    As you might have noticed, not all files that were downloaded by Composer in step 1, have been staged for commit by Git. Certain files and folders, such as the project's dependencies (which are managed by Composer), parameters.yml (which contains sensitive information such as database credentials), log and cache files and dumped assets (which are created automatically by your project), should not be committed in Git. To help you prevent committing those files and folders by accident, the Standard Distribution comes with a file called .gitignore, which contains a list of files and folders that Git should ignore.

    Tip

    You may also want to create a .gitignore file that can be used system-wide. This allows you to exclude files/folders for all your projects that are created by your IDE or operating system. For details, see Github .gitignore.

  4. Create an initial commit with your started project:

    $ git commit -m "Initial commit"

At this point, you have a fully-functional Symfony2 project that's correctly committed to Git. You can immediately begin development, committing the new changes to your Git repository.

You can continue to follow along with the :doc:`/book/page_creation` chapter to learn more about how to configure and develop inside your application.

Tip

The Symfony2 Standard Edition comes with some example functionality. To remove the sample code, follow the instructions in the ":doc:`/cookbook/bundles/remove`" article.

Vendors and Submodules

Instead of using the composer.json system for managing your vendor libraries, you may instead choose to use native git submodules. There is nothing wrong with this approach, though the composer.json system is the official way to solve this problem and probably much easier to deal with. Unlike Git submodules, Composer is smart enough to calculate which libraries depend on which other libraries.

Storing your Project on a Remote Server

You now have a fully-functional Symfony2 project stored in Git. However, in most cases, you'll also want to store your project on a remote server both for backup purposes, and so that other developers can collaborate on the project.

The easiest way to store your project on a remote server is via a web-based hosting service like GitHub or Bitbucket. Of course, there are more services out there, you can start your research with a comparison of hosting services.

Alternatively, you can store your Git repository on any server by creating a barebones repository and then pushing to it. One library that helps manage this is Gitolite.