Using Git with Symfony2 and Netbeans

16 September 2012 Johan Hornof

Some short time ago, we started to use Git for our software projects. As we develop a lot with the Symfony2 framework using NetBeans as an IDE, there were no doubts that all should work seamlessly also together with Git.


Of course, there were some issues

  • Netbeans can ignore only directories, not files
  • Cache is ignored by default but this does not apply for logs
  • in the vendor directory, other git repos are present
  • the .gitignore file is "ignored" by NetBeans and thus not committed and pushed

Here is how to init the repository and do the first commit and pull with the right git settings.

1. Create the Symfony2 project in NetBeans

Download the framework from here: or create from existing sources.

2. Init the repository

This can be done either from NetBeans or from terminal git init

3. Close the project in NetBeans

This is important, otherwise the IDE goes crazy while doing changes in the project from terminal.

4. Setup ignores

Go in the project folder via command line, open the .gitignore file located in the project root directory (create one if necessary) Put this inside:


(if you use custom vendors packages, you can ignore only default folders from vendors separately).
You may want to ignore some more folders e.g. web/uploads or similar.

5. Add and commit

git add .
git commit -a -m 'initial commit'

Check that you have everything committed... just in case...

$ git status
# On branch master nothing to commit (working directory clean)

If something is still not committed, commit the files/folders seprately.

6. Add remote repository

(you can do this also later from NetBeans)

git remote add origin user@server:/folder

7. Push into the remote repository

(you can do this also later from NetBeans)

git push origin master

8. Open the project in NetBeans

...and you can see the right files being written in gray - that means they're ignored.

9. Pulling the repository elsewhere

When pulling from the remote repository elsewhere, do not forget about the ignores. You'll have to check .gitignore and copy manually vendors and prameters.ini.

Also don't forget about:

mkdir app/cache app/logs
chmod 0777 app/cache app/logs