Yii 1.1: Starting your Yii Project Reference Guide (with Git VCS in Linux)

13 followers

I've found useful to have a step by step reference guide to work with Git with most used commands, feel free to update it with useful information you may find interesting too.

Getting Yii from Github

$ git clone https://github.com/yiisoft/yii.git

Working with your project

Start your project

(being at root folder)

$ yii/framework/yiic webapp myproject
$ cd myproject

Initialize git

$ git init

Make git add empty directories to the repository

for i in $(find . -type d -regex ``./[^.].*'' -empty); do touch $i"/.gitignore"; done;

(source https://gist.github.com/18780 )

Adding third-party extensions

Adding a yii extension repository inside your repo at a specific path (e.g. we will add https://git.gitorious.org/lightopenid/lightopenid.git in 'protected/extensions/lightopenid')

git submodule add https://git.gitorious.org/lightopenid/lightopenid.git protected/extensions/lightopenid

This creates the file .gitmodules in your root folder which tracks all your modules data.

if for some reason (older git versions, cloning from another location) you end up with an empty directory where a foreign repository should be:

git submodule update --init

should fix it. Then you can update your repository and external ones with:

git pull && git submodule update --recursive

To remove a submodule:

git rm --cached protected/extensions/lightopenid

Ignoring files

Edit .gitignore file in root folder and add dirs/files you don't want to be in git repo Use ! to negate the pattern:

assets/*
!assets/.gitignore
protected/runtime/*
!protected/runtime/.gitignore
protected/data/*.db

Adding your own forked repo from github as an extension

If you want to add your forked repo from github ( i.e.: git@github.com:marcanuy/Comments-module.git ) from another repo (i.e.: git://github.com/segoddnja/Comments-module.git) to the extensions directory, then:

git submodule add git@github.com:marcanuy/Comments-module.git protected/Comments-module
cd protected/extensions/Comments-module
git remote add upstream git://github.com/segoddnja/Comments-module.git

Then every time you wish to get latest updates from the original repo you should do:

cd protected/extensions/Comments-module
git pull upstream master

Make your first commit

git commit -a "Initial version"

Now you are ready to go!

Total 5 comments

#14778 report it
Kudzu at 2013/09/09 05:52am
Yiic webapp git

You could create all necessary dirs with git files but setting vcs parameter:

yiic webapp <app path> git

I think article needs to be updated.

#12058 report it
Versus at 2013/02/25 01:28pm
Forgot /extentions/

This line

git submodule add git@github.com:marcanuy/Comments-module.git protected/Comments-module

should be like this

git submodule add git@github.com:marcanuy/Comments-module.git protected/extensions/Comments-module
#8085 report it
Mukke at 2012/05/09 08:18am
git init

@sensorario:

you need the init for your own project

for example

myproject <- directory with your code in

myproject/yii <- directory with the yii git repo in

ofc i added yii as a submodule in myproject

#7055 report it
marcanuy at 2012/02/21 02:11pm
Re: Why init again a git project?

Hi sensorario,

$git init

was not meant to run in yii folder, but in your project folder. This way you create an independent repository from your Yii fork just for your project.

#7052 report it
sensorario at 2012/02/21 01:34pm
Why init again a git project?

I dont understand why you launch command

$ git init

in yii folder ofter cloning. When you clone a project on github, you have already a git project.

Leave a comment

Please to leave your comment.

Write new article