How to checkout a new branch from other branch or tag with git checkout

Today I learned a new way to checkout a new branch from other branch or a tag.

Normal way width git branch & git checkout


git branch new_branch base_branch

git checkout new_branch

Only with git checkout


# creates and checkout the new branch from the base branch
git checkout base_branch -b new_branch

# creates and checkout the new branch from the tag
git checkout tag_name -b new_branch

How to delete master branch from git server

Today I needed to remove the master branch from a remote repository, but when I did it I got this message:


git push origin :master

remote: error: By default, deleting the current branch is denied, because the next

remote: error: 'git clone' won't result in any file checked out,
causing confusion.
remote: error:
remote: error: You can set 'receive.denyDeleteCurrent' configuration variable to
remote: error: 'warn' or 'ignore' in the remote repository to allow deleting the
remote: error: current branch, with or without a warning message.
remote: error:
remote: error: To squelch this message, you can set it to 'refuse'.
remote: error: refusing to delete the current branch: refs/heads/master
To ssh://server_name/git/repository.git
! [remote rejected] master (deletion of the current branch prohibited)
error: failed to push some refs to 'ssh://server_name/git/repository.git'

By default the git server does not allow to delete the current branch (usually is the master branch) , but you can change this behavior by doing the following steps:

ssh git_server_ip -l root
sudo -u git_user git config --system receive.denyDeleteCurrent warn
sudo -u git_user git config --global receive.denyDeleteCurrent warn

See more details about receive.denyDeleteCurrent.

How to install and configure the Jira Git plugin with Gitlab

Introduction

Before I continue let me tell you that the Jira Git Plugin that I will talk about is not supported by Atlassian but Marcello Teodori added support for version 5 of Jira.  If you want a supported plugin you can see the Git Version Control Viewer supported by BigBrassBand, I will not talk about it because I didn’t try it.

Requirements

Let’s start

First of all, you should know that it can be done with two different environments:

  1. Having Jira in one server and Gitlab with git in other server
  2. Have both in the same server

Step 1 – Install the Jira Git Plugin

  1. Open Jira
  2. Go to: Administration > Plugins > Manage Plugins
  3. Click on “Upload Plugin”
  4. Add the url for the plugin: https://github.com/downloads/mteodori/jira-git-plugin/jira-git-plugin-0.6.1-SNAPSHOT.jar
  5. Click on upload

By now you should have Jira Git Plugin installed.

Step 2 – Configure the Git repositories

For every single repository you will need to clone it and add the configuration for it inside Jira. Since you can have two different environments let’s do it for both.

1. Jira and Gitlab on the same server

  1. git clone (with or without –bare) the source tree that you need (run as the same user that Jira runs as). Ex.: git clone –bare git@localhost:test /home/jira/repositories/test
  2. Go to: Open Jira > Administration section > Plugins > Git Repositories > click on Add
  3. Display Name: Your repository name. Ex.: Test
  4. Repository root: Directory where you cloned your repository. Ex.: /home/jira/repositories/test
  5. Repository Origin: The url you used to clone the repository. Ex.: git@localhost:teste.git
  6. Web Linking: For the current version of Jira Git Plugin does not exist the default Gitlab formats but you can add them manually:
    1. View format: http://<gitlab server>/<repository>/master/tree
    2. Changeset format: http://<gitlab server>/<repository>/commits/${rev}
    3. File added, modified and deleted are the same formar: http://<gitlab server>/<repository>/commits/${rev}#${path}

2. Jira and Gitlab on different servers

You have two choices here:

  1. Add the private ssh key of gitlab user to the user that Jira runs
  2. Create a new user on Gitlab for Jira and generate the ssh key for that user on the Jira server.
First one:
  1. Copy the ssh key of the gitlab user (on the Gitlab server) to the user that Jira runs as (on Jira server)
  2. Now you can follow the Jira and Gitlab on the same server steps

Second one:

  1. Generate the ssh key for the user that Jira runs as (on Jira server)
  2. Create the Jira user inside Gitlab
  3. Add the public ssh key for the user that you create on step 1
  4. Add the user to the repositories you want (at least with the reporter role)
  5. Now you can follow the Jira and Gitlab on the same server steps

edited:  added the Jira version supported by this plugin

Composer Plugin for Oh My Zsh

About Oh My Zsh

Is community-driven framework for managing your zsh configuration. It has more than 40+ plugins (git, symfony2, OSX, gem, ruby, etc) with a lots of handful functions, autocomplete feature and lots of useful alias. Also it brings a very good variety of themes or you can customize your own.

About Composer

Is a tool for dependency management in PHP. It’s not a package manager but it deals with packages in a per project basis. See the composer documentation.

The Plugin

This is a very simple plugin for Oh My Zsh that adds composer autocomplete feature and useful aliases:

c = 'composer'
c <tab> for autcomplete
csu = 'composer self-update'
cu = 'composer update'
ci = 'composer install'
ccp = 'composer create-project'
cget = installs composer on the current path

In the composer documentation you can find all the cli commands.

To add the plugin you need to make sure that your Oh My Zsh is updated. Then edit your .zshrc file:


vim ~/.zshrc

Find the plugins line and add composer to the end:

...

plugins=(git .... composer)

If you have any suggestions, I would love to hear about them.

LXJS – A Conference to be repeated

LXJS logo

Last weekend  took place of the most amazing conferences that I have been  lxjs 2012!

A 2 day non-profit international conference about Javascriptthat was organized by the community and for the community.

Workshop and Pre-Party

The day before the conference starts, was the day of the workshops and the pre-party. The workshop I have been was the JS Client Side Testing.

It gave me the perception when should I do UI tests and how to do them with Selenium. Also the guys from Sauce Labs have a great product to run the tests in all browsers and OS. The pre-party at Florida After Seven was very cool. With a relaxed environment, great to meet and talk with lots of music, drinks and snack was a great preparation for day 1!

Day 1

Swaggggggg!! Lots of swag from the sponsors, but the one I most liked was the amazing and tasty “Pastéis de Belém” sponsored by Mozilla. The talks in the overall were good, as usual some talks were better than others. The 4 talks I liked most were:

Here is the all talks of day 1. Congratulations to the acavideo.com guys for the awesome work they did on the videos.

The party had place in an amazing bar named “Pensão Amor”, near to the conference venue and Bairro Alto where was served lots of drinks, snacks with good music.

Day 2

After a few hours of sleep, the day 2 started. Another set of good talks, you can find the videos of them here. The talks I liked most were:

The boat party was amazing, I had forgotten how amazing is Lisbon seen from the river. It reminds me the times I studied at etic_. The drinks and snacks served at the boat were very good and tasty, it was the perfect place to finish the conference and to catch up some people to talk with.

Congratulations to the Organization for the fantastic conference. I really hope for LXJS 2013!

A huge thanks to Geeklist for sponsoring me with a ticket to the event. Was fantastic to spread the Geeklist word amoung all the JS geeks.

This conference was a fountain of inspiration for me. It took me to think why can’t PHP Community in Portugal do something like this? This conference will give a huge boost to the PHP Comunnity here in Portugal I can ensure that.

See you guys next year! (I hope)

My talk about AngularJS with ASP.NET MVC

This weekend I gave my first talk at NetPonto community. The talk was an introduction to AngularJS with ASP.NET MVC 4. My main goal was to explain the basics of AngularJS and how it works and do some demos.

You can see the code samples here and the slides below.

Note: This talk was in portuguese and also the slides are in portuguese.

http://speakerdeck.com/u/danielcsgomes/p/introducao-ao-angularjs-com-asp-dot-net-mvc-4

ZCE PHP 5.3

I’m very happy because I passed the Zend Certified Engineer PHP 5.3 exam. This certification is very important to me because it proves my knowledge on PHP language that complements with my 7+ years of experience.

The Exam

  • The exam isn’t easy but is not so harder too! You only need to be calm and relax.
  • My strategy was answer all the questions I know and mark with a flag the others to review at the end.
  • When you finish the question a review panel appears telling you if you have incomplete questions or not. There you can review all questions, flagged questions or incomplete questions. First I reviewed the incomplete questions, next the flagged and before ending the exam I review all questions.
  • This last review I read everything again to make sure there aren’t pitfall questions that I didn’t saw.
  • About questions and answers I can’t talk about it because of the disclosure agreement I had to sign.

How did I study

  • This last year, I programmed with Microsoft Technologies like C#, C++, ASP.NET MVC in my daily basis. Because of that, I felt the necessity to practice almost every topics from basic to advance with PHP. I created a repository on github with the code I did to study.
  • I practise almost 200 sample questions from phpriot and ucertify. This samples give me some orientation about what I could face on the exam itself.
  • The PHP manual is the best source of information and almost everything as a very good explanation.

This certification was a wonderful journey. I want to thanks to my wife, family and friends for the support.

How to create a custom Filter with AngularJS v1.0

A few days ago I needed to create a custom filter to truncate a piece of text with a specific length and with a custom ending, something like this: “This is an Examp…”.

Before I continue, I want to refer that AngularJS is on version 1.0. At this version the documentation is not yet completed.

The creation of custom filters only needs three things:

  1. Create the module
  2. Create the filter and his function
  3. Register the module in the application

1. Create the module

angular.module('yourModuleName', [])

2. Create the filter and his function

angular.module('yourModuleName', [])
    .filter('yourFilterName', function () {
        return function () {
            return;
        };
    });

3. Register the module in the application

angular.module('yourAppName', ['yourModuleName']);

Example: Truncate Filter


angular.module('filters', []).
    filter('truncate', function () {
        return function (text, length, end) {
            if (isNaN(length))
                length = 10;

            if (end === undefined)
                end = "...";

            if (text.length <= length || text.length - end.length <= length) {
                return text;
            }
            else {
                return String(text).substring(0, length-end.length) + end;
            }

        };
    });

You can see this example on this gist and run it on jsfiddle.

Note: This can not be the best practice implementation, but was the result I achieved and solved my problem.

The Multitasking Name Game – Portuguese Version

About the game

This game is intended to demonstrate a simple and practical way of the problems and disadvantages of multi-tasking.

This is the Portuguese version translated from the “The Multitasking Name Game” created by Henrik Kniberg.

Duration

  • 10 Minutes to explain the game
  • 20 Minutes to discuss implementation and

Documents