Guide for getting started with GIT

create a new repository

create a new directory, open it and perform a
git init
to create a new git repository.

checkout a repository

create a working copy of a local repository by running the command
git clone /path/to/repository
when using a remote server, your command will be
git clone username@host:/path/to/repository

workflow

your local repository consists of three “trees” maintained by git. the first one is your Working Directory which holds the actual files. the second one is the Index which acts as a staging area and finally the HEAD which points to the last commit you’ve made.

add & commit

You can propose changes (add it to the Index) using
git add <filename>
git add *
This is the first step in the basic git workflow. To actually commit these changes use
git commit -m "Commit message"
Now the file is committed to the HEAD, but not in your remote repository yet.

pushing changes

Your changes are now in the HEAD of your local working copy. To send those changes to your remote repository, execute
git push origin master
Change master to whatever branch you want to push your changes to.

If you have not cloned an existing repository and want to connect your repository to a remote server, you need to add it with
git remote add origin <server>
Now you are able to push your changes to the selected remote server

branching

Branches are used to develop features isolated from each other. Themaster branch is the “default” branch when you create a repository. Use other branches for development and merge them back to the master branch upon completion.

create a new branch named “feature_x” and switch to it using
git checkout -b feature_x
switch back to master
git checkout master
and delete the branch again
git branch -d feature_x
a branch is not available to others unless you push the branch to your remote repository
git push origin <branch>

update & merge

to update your local repository to the newest commit, execute
git pull
in your working directory to fetch and merge remote changes.
to merge another branch into your active branch (e.g. master), use
git merge <branch>
in both cases git tries to auto-merge changes. Unfortunately, this is not always possible and results in conflicts. You are responsible to merge those conflicts manually by editing the files shown by git. After changing, you need to mark them as merged with
git add <filename>
before merging changes, you can also preview them by using
git diff <source_branch> <target_branch>

tagging

it’s recommended to create tags for software releases. this is a known concept, which also exists in SVN. You can create a new tag named 1.0.0by executing
git tag 1.0.0 1b2e1d63ff
the 1b2e1d63ff stands for the first 10 characters of the commit id you want to reference with your tag. You can get the commit id by looking at the…

log

in its simplest form, you can study repository history using.. git log
You can add a lot of parameters to make the log look like what you want. To see only the commits of a certain author:
git log --author=bob
To see a very compressed log where each commit is one line:
git log --pretty=oneline
Or maybe you want to see an ASCII art tree of all the branches, decorated with the names of tags and branches:
git log --graph --oneline --decorate --all
See only which files have changed:
git log --name-status
These are just a few of the possible parameters you can use. For more, see git log --help

replace local changes

In case you did something wrong, which for sure never happens ;), you can replace local changes using the command
git checkout -- <filename>
this replaces the changes in your working tree with the last content in HEAD. Changes already added to the index, as well as new files, will be kept.

If you instead want to drop all your local changes and commits, fetch the latest history from the server and point your local master branch at it like this
git fetch origin
git reset --hard origin/master

useful hints

built-in git GUI
gitk
use colorful git output
git config color.ui true
show log on just one line per commit
git config format.pretty oneline
use interactive adding
git add -i

Add Toolbar and pager to custom product collection in magento

While handling a magento job, i encountered a situation to implement the toollbar section for a custom product collection. So today we are discussing about how to add Toolbar and pager to custom product collection in magento

Let us assume $_productCollection is an object of custom product collection.

First we need to create a toolbar object as shown below

$toolbar = Mage::getBlockSingleton('catalog/product_list')->getToolbarBlock();

Then Assign product collection to toolbar object

$toolbar->setCollection($_productCollection);

then set pager to toolbar as a child for show with pagination

  $pager = Mage::getSingleton('core/layout')->createBlock('page/html_pager');
 $toolbar->setChild('product_list_toolbar_pager', $pager);
 echo $toolbar->toHtml();

So this is how we can add Toolbar and pager to custom product collection in magento, hope this helps

Magento New Malware Issue

There has been recent reports on a new malware that appears to capture details from all fields of the checkout process, including the credit card information. Its been done using Database or Admin access to get the details. Magento team do not have the details on how attackers are getting the Admin access, may they are going for weak passwords and some unpatched sites or using admin accounts set up before the site was patched.

Scan your site at magereport.com to check whether the site is at risk for a Credit Card Hijack and also don’t forgot to check you have any unknown Admin users in the site. You need to scan the code for the malware and some may includes onepage|checkout and can be found in two sections:

  • Admin->Configuration->General->Design->HTML Head->Miscellaneous Scripts, or
  • Admin->Configuration->General->Design->Footer-> Miscellaneous HTML

If the site is infected, immediately remove this malware and check you code for any unknown changes and remove any unknown Admin accounts and update all admin passwords to prevent further access to the website

Please check the information provided by Magento in their site for best security practices.

Migrating wordpress to another server

For blogger who self-hosts the WordPress blog publishing system on a web hosting server with own registered domain name, sometimes, you may decide to reorganize the blog link URL to make it tidier or to reflect new focus or theme of the blog. If you decide to change the URL or link location of your WordPress blog due to changing of domain name (such as from http://www.old-domain.com/ to http://www.new-domain.com/) or the blog to another directory location (such as from http://www.domain.com/ to http://www.domain.com/blog/), there are some steps that should be done to ensure the proper migration and no breaking links.

The tricky part when moving WordPress blog to another location is that WordPress is using absolute path in URL link instead of relative path in URL link location when stores some parameters in database. Within blog posts’ contents itself, users may also use the old URLs when creating reference backlinks. All these values in the database will need to be changed when WordPress is moved. The following guide will show you which database fields that has references or values related to blog’s URLs that you want to modify. Note that this guide is not about how to move WordPress blog from one server or host to another new hosting service.

Once the blog has been moved (all files copy over in case of moving location or server or new domain name properly propagated across Internet for new domain name), the first thing to change is to tell WordPress the new blog location (wp-config.php should be no changes, and .htaccess file should be also no changes. If for some reason mod_rewrite rules for friendly URLs no longer works, you can always regenerate the .htaccess file via WP Administration’s Update Permalinks page). This value can be changed via WordPress Options page, but if you no longer able to access to old blog URL, you have to modify the value via MySQL database.

In this post we are using  MySQL replace() function to change the urls in the database. To run the query we need to login to the phpmyadmin section using the username and password

We can use the below MySQL query to update the WordPress options with the new url:

UPDATE wp_options SET option_value = replace(option_value, ‘http://www.old-url.com’, ‘http://www.new-url.com’) WHERE option_name = ‘home’ OR option_name = ‘siteurl’;

Now we need to change the guid from the wp_posts table, The URL values are stored as absolute URLs instead of relative URLs and that’s too be changed with the below stated SQL query:

UPDATE wp_posts SET guid = replace(guid, ‘http://www.old-url.com’,’http://www.new-url.com’);

If we have added media’s inside the content area section, they are added with the absolute URLs, So use this query to change the internal links added in the content area

UPDATE wp_posts SET post_content = replace(post_content, ‘http://www.old-url.com’, ‘http://www.new-url.com’);

Now we are done on changing the url and now we need to check on the front-end to make sure that everything works fine