git clean - Cleaning the Git repository to be able to merge with remote

Submitted by Peter Majmesku on Mon, 08/29/2016 - 20:06

Sometimes you get Git messages like

The following untracked working tree files would be overwritten by checkout

 The following command can be helpful in that case.

git clean -d -fx ""


-x means ignored files are also removed as well as files unknown to git.
-d means remove untracked directories in addition to untracked files.
-f is required to force it to run.

 I've learned this by a discussion on Stackoverflow:


Rsync: Sync Two Folders via SSH in Both Directions

Submitted by Peter Majmesku on Mon, 08/29/2016 - 20:04

After started writing about rsync from local to live. Here's a post about syncing in two directions.

Helpful in rsync is, that also the permissions- and owner information is transfered ("-a" parameter). The "--progress" parameter shows the progress and "--exclude" allows to exclude directories. Be carefully about "--delete". Mind hidden folders like ".git" and ".vagrant" etc.

SSH session on local system (developer desktop) to sync files from (stage/live) server to local system

Here we assume you are in a ssh session on your local development environment and you want to sync from the stage/live server to your local development environment.

rsync -a source/ destination-host:/destination-directory/


rsync -a --progress www/ --exclude=sites/default/files/ --exclude=.idea/ --exclude=.vagrant/ --exclude=provisioning/ --exclude=.git

From (stage/live) server to local system (developer desktop)

Here we assume you are in a ssh session on your stage/live server and you want to sync from your local development environment to stage/live server.


rsync -chavzP --stats --progress /var/www/some-folder/ 

Detailed explanation for the commands can be found at The rsync command above is explained here.

Happy syncing.

Rsync without changing permissions

The following command will sync the files and folders. It will also delete. But it will not change the permissions. It can be helpful, if you want to ensure, that your webserver is still able to read and execute the files. Like in a case, where I needed this command.

rsync -a --no-perms --progress --delete ./ user@host:/var/www/some-directory/

Drush: Rebuild the cache of a single Drupal (8) site in a multi-site setup with the magic "-l" parameter

Submitted by Peter Majmesku on Mon, 08/29/2016 - 20:02

After lots of googling, testing, reading and so on, I've finally found out the Drush command to flush the cache of a single Drupal (8) site in a multi-site setup.

drush -l 8888.notes cache-rebuild

If your site is located at /sites/8888.notes you need the command above. The "-l" parameter is necessary. I could not find out what "-l" means, but this parameter seemed necessary. 


GitHub not accepting public SSH key: fix it by switching from HTTP(S) to SSH in the Git repository config

Submitted by Peter Majmesku on Mon, 08/29/2016 - 19:57

If you clone a Git repository from GitHub via the HTTPS URL, which is placed in the section as shown below, than your public SSH key will not be recognized by GitHub.

You can test your public SSH key for GitHub usage by the following command:

ssh -T

If you have chosen the wrong HTTPS option before (it must be SSH), you can fix that by the following steps.

  1. Open the file at .git/config
  2. Look for 
    url = or url =
  3. Replace it by
    url = ssh://
  4. Save the file and GitHub will accept the public SSH key on the next push. No username and password typing anymore.

Fix Line Endings Between Various File Systems

Submitted by Peter Majmesku on Mon, 08/29/2016 - 19:56

If you work sometimes on Windows, sometimes on Mac and sometimes on Linux, you can get troubles with line endings. Programs which aren't smart enough to detect line endings by them self, will display the text as if the file contained no line breaks at all.

  • Windows, and DOS before uses a pair of CR and LF characters to terminate lines
  • UNIX (Including Linux and FreeBSD) uses an LF character only. 
  • OS X also uses a single LF character 
  • Classic Mac operating system used a single CR character for line breaks. 

That's tricky. A tool for fixing line endings is "SFK - The Swiss File Knife File Tree Processor". It's mentioned at

All you have is to use the following command for converting to Mac OSX:

sfk remcr -dir your_project_directory

Git: Fixing "error: src refspec BRANCHNAME matches more than one."

Submitted by Peter Majmesku on Mon, 08/29/2016 - 19:50
Sometimes it happens, that there're more heads with the same name in the Git repository. That can happen by copy and pasting folders. To delete any duplicate head, the following command can be used.
git push origin --delete refs/heads/BRANCHNAME
Then the last command, which will bring it to work again:
git push origin BRANCHNAME

Yii2: Bring the assets from your module to your view

Submitted by Peter Majmesku on Mon, 08/29/2016 - 19:34

If you want to ship assets (JavaScript, CSS files) from your Yii2 module to your view, you can do that elegant with a couple of simple steps.

1., Folder structure

We assume that your Yii2 module is located at


The assets are at


So the JavaScript files are at


2., Set an alias to your assets in your Module.php in your module (/yii-base-folder/modules/YOUR-YII-MODULE-FOLDER/Module.php)

namespace app\modules\MY-MODULE;
Module extends \yii\base\Module
$controllerNamespace 'app\modules\MY-MODULE\controllers';
    public function 
'@MY-MODULE-assets' => __DIR__ '/assets'

3., Put your asset class into your assets folder to setup your "assets bundle"

We name a bunch of assets "assets bundle". Here you declare your files and make it accessible to your view.

namespace app\modules\MY-MODULE\assets;
MyModuleAsset extends AssetBundle
// the alias to your assets folder in your file system
public $sourcePath '@yiipass-assets';
// finally your files.. 
public $css = [
$js = [
// that are the dependecies, for makeing your Asset bundle work with Yii2 framework
public $depends = [

4., Now you can access your assets from your view

We assume that your view's index.php file is located at /yii-base-folder/modules/YOUR-MODULE/views/ANY-VIEWS-SUBFOLDER/index.php

// that class is usually used, if you work with html in your view.
use yii\helpers\Html;
// here comes your Yii2 asset's class!
use app\modules\YOUR-MODULE\assets\YOUR-ASSER-CLASS;
// now Yii puts your css and javascript files into your view's html.

  Some <strong>HTML</strong> my <i>friend..</i> :)
</p> ?>

5., Conclusion

Now Yii2 puts your CSS and JavaScript files nicely into your HTML. By default the JavaScript files will be put nicely into the footer of your HTML. Also the CSS and JavaScript files will be copied into your web-accessible assets folder. The users from your webpage will not be allowed to get info about your Yii project folder structure. So the path to your JavaScript file will look like that: 

<script src="/assets/3598bbc6/js/YOUR-JavaScriptFile.js"></script

The path in your project's directory will be:

Also the PHP asset class will be copied from your module's folder:

Don't forget to not modify the files at /YOUR-Yii2-PROJECT/web/assets/3598bbc6/ manually, because they're created automatically by the Yii2 framework.

6., Learn more

The "The Definitive Guide to Yii 2.0" is mostly the best first place to learn about Yii2. So you find more detailed information about the assets functionality at the assets chapter. I recommend also to read the excellent PHP class comments in the Yii2 core. Like f.e. /YOUR-Yii2-PROJECT/vendor/yiisoft/yii2/web/AssetBundle.php. Yii2 is one of the few OpenSource projects where the PHP code itself can often lead you to your goals.


MySQL: Import and export compressed data

Submitted by Peter Majmesku on Mon, 08/29/2016 - 19:24

The export (dump)

This command will generate you a compressed dump file with the date information in the filename.

mysqldump -u username -p"password" database_name | gzip > $(date +"%Y-%m-%d")-database_name.sql.gz

Import the database dump

Firstly make sure that the "empty" database exists. Then import it:

mysql -uUSERNAME -p"PASSWORD" database_name < dump-filename.sql

Import a Gzip compressed database dump file:

zcat database-dump-file.sql.gz | mysql -uroot -ppassword database-name

Yii2: Access your services within your module

Submitted by Peter Majmesku on Mon, 08/29/2016 - 19:22

There're some ways to declare the service in your config file for global use, but I wanted a way to setup my service in my module. Well, it took me a while so I write the way down here to look back in future to not search around the web.

Firstly you need to declare the service in your module:

namespace app\modules\MY-MODULE;
Module extends \yii\base\Module
$controllerNamespace 'app\modules\MY-MODULE\controllers';
    public function 
// Declare services. Let's say you need the XmlService.
$this->set('xml', new services\XmlService());

Afterwards you can access your module wherever you want to (note the cast for handier usage in your IDE):

/* @var $xml app\modules\yiipass\services\xml */
$xml = \Yii::$app->getModule('MY-MODULE')->get('xml'); 

Eclipse mit Plugins zur PHP IDE rüsten

Submitted by Peter Majmesku on Mon, 08/29/2016 - 19:20

Hallo zusammen,
da ihr viele meist Remote arbeitet und da auch eine PHP IDE nützlich ist, ist Eclipse nicht schlecht. Im Gegensatz zu Netbeans oder PhpStorm lädt Eclipse mit dem Remote System Explorer Plugin die Dateien nicht herunter. Zudem sind Calltips für PHP Befehle und das Springen zu Funktionsdeklarationen möglich (Remote sobald die Datei mit den Deklarationen einmal geöffnet wurde). Man springt z.B. mit STRG + Klick mit linker Maustaste auf Funktionsaufruf im Code. 

Das Cacheing der Deklarationen klappt mit dem letzten Punkt in der unten aufgeführten Anleitung. Probierts mal aus. Ist eine gute OpenSource IDE für PHP Entwicklung, gerade wenn ihr Remote arbeitet, nicht einzelne Projekte anlegen und den Code herunterladen wollt.

Beim Umsetzen "das Ganze" Tutorial durchgehen. ;)