git branching model

git

git is a tool for the command line to backup and distribute source code. There are multiple beautifully made webpages and GUI tools which help to use it and to make sense out even out of the biggest code bases.

The workflow is simple: Each code base / each project is in its own repository. As soon as you’ve finished a change or a feature you commit (save) your code. You can switch back and forth between commits and can compare the changes you’ve made. If you want to share or backup your repository, you push (upload) it to a git hoster. Other participants in your project can pull (download) your repository, including all commits you’ve made. One repository can have multiple branches (versions of your code), each of those has its own commits. Branches can be merged (united) and created.

As a hoster for git I can recommend github which is perfect for open source projects, and gitlab if you need a lot of private repositories. Both services are free, at the time of writing github has some more useful features (like project management with Kanban) compared to gitlab, but both services do a very good job with hosting and helping you make sense out of large repositories.

As committing, pulling, pushing may be complicated for new users I recommend a GUI application to do those steps for you, until you feel confident to use the command line. One of the best is gitkraken, github even provides its own desktop client.

Git is very handy as a backup tool, but it can also help you to structure different versions of your code, allows you to do code reviews and to allow statistics about the overall progress of the repository.

Branching may be confusing for new users, but if integrated in your workflow in a sensible way it is a very handy tool to allow work on different features and versions of your software in a sensible way. How to name and organize your branches is explained very well in a tutorial on the webpage from atlassian.
Another very well written (but a bit more technical) post to branching concepts can be found on the blog of nvie

set up symfony

Prerequisites

  • installed XAMPP or MAMP (apache server & php installation bundles)
  • installed composer (php libraries)
  • installed npm (deploy libraries)

Step 1: install Symfony installer

option 1 (recommended): download the installer, and move it to the directory where your repository should be located

php -r "readfile('https://symfony.com/installer');" > symfony
move symfony D:\Repos
php symfony new my_project

option 2: create the project with composer:

composer create-project symfony/framework-standard-edition my_project

follow the instructions in the console (you will probably need to configure your database & mail settings)

now, update all packages with composer:

composer update

Step 2: set up npm

create a file named package.json, adapt following json to your needs:

{
  "name": "my_project",
  "version": "0.1.0",
  "description": "My Project",
  "repository": {
    "type": "git",
    "url": "git://github.com/famoser/my_project.git"
  },
  "keywords": [
    "office",
	"online"
  ],
  "author": "Florian Moser <git@famoser.ch>",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/famoser/my_project/issues"
  },
  "homepage": "https://github.com/famoser/my_project",
  "devDependencies": {
    "bower": "^1",
    "browser-sync": "^2",
    "del": "^2",
    "gulp": "^3",
    "gulp-all": "^1",
    "gulp-batch": "^1",
    "gulp-bower": "^0",
    "gulp-clean-css": "^2",
    "gulp-concat": "^2",
    "gulp-less": "^3",
    "gulp-notify": "^2",
    "gulp-rename": "^1",
    "gulp-sass": "^2",
    "gulp-sourcemaps": "^1",
    "gulp-uglify": "^1",
    "gulp-watch": "^4",
    "less-plugin-autoprefix": "^1",
    "rimraf": "^2"
  }
}

run in your console

npm update

Step 3: set up bower

create a file named bower.json, adapt following json to your needs:

{
  "name": "my-project",
  "version": 0.1,
  "homepage": "https://github.com/famoser/my-project",
  "authors": [
    "famoser <git@famoser.ch>"
  ],
  "description": "My Project",
  "keywords": [
    "php"
  ],
  "license": "MIT",
  "ignore": [
    "**/.*",
    "node_modules",
    "bower_components",
    "test",
    "tests"
  ],
  "dependencies": {
    "jquery": "2.2.3",
    "bootstrap": "3.3.6",
    "components-font-awesome": "*"
  }
}

create a file named .bowerrc, with following json content:

{
    "directory": "web/assets/vendor/"
}

to create such a strange filename you can run

copy NUL > .bowerrc

in your console.

Step 4: set up build tools

I’ll use gulp for this.
Create a file named guldfile.js, content must be JavaScript. You’ll find a good starting point here: gist. There is quite a lot going on in this file, the instructions and the configuration is at the top.

Now run in your console

gulp

to build all frontend libraries for the first time.

Step 5: set up source control

  • add a README.MD describing your project
  • add a LICENSE.MD so other users may or may not be allowed to use your work (I’m recommending the MIT license)
  • exclude unnecessary files from git (bower, composer & IDE files)
.idea
node_modules
/web/assets/vendor
symfony-scripts/.git

Step 6: rename your AppBundle

choose a custom name for your application, make it VendorApplicationBundle, so for example GoogleYoutubeBundle.
Files / Folder you need to adapt:

  • The file /src/AppBundle/AppBundle.php
  • The namespaces in all .php files inside /src/AppBundle/**/*.php
  • The folder /src/AppBundle
  • in /app/AppKernel.php you need to register your renamed bundle (just replace the old AppBundle/AppBundle entry)
git

git hooks on windows

In $GIT_DIR/hooks/* (typically in <repository_root>/.git/hooks/*) you may place scripts, which execute as you perform specific git operations on your repository. For more info on how to name the hooks and when exactly they are executed, type in git help hooks in your console.

However, you are not able to use commands you know from .cmd and .bat files. Instead, place this in your hook (for example post-checkout):

cd ./.git/hooks
start post-merge.cmd

now post-merge.cmd (placed in the same folder as the hooks) is called and executed by the hook.