git command cheat sheet - short description

GIT command cheat sheet with short descriptions

Git taskNotesGit commands
Tell Git who you are Configure the author name and email address to be used with your commits.Note that Git strips some characters (for example trailing periods) from git config --global "Sam Smith"
git config --global
Create a new local repository git init
Check out a repository Create a working copy of a local repository: git clone /path/to/repository
For a remote server, use: git clone username@host:/path/to/repository
Add files Add one or more files to staging (index): git add <filename>git add *
Commit Commit changes to head (but not yet to the remote repository): git commit -m "Commit message"
Commit any files you've added with git add, and also commit any files you've changed since then: git commit -a
Push Send changes to the master branch of your remote repository: git push origin master
Status List the files you've changed and those you still need to add or commit: git status
Connect to a remote repository If you haven't connected your local repository to a remote server, add the server to be able to push to it: git remote add origin <server>
List all currently configured remote repositories: git remote -v
Branches Create a new branch and switch to it: git checkout -b <branchname>
Switch from one branch to another: git checkout <branchname>
List all the branches in your repo, and also tell you what branch you're currently in: git branch
Delete the feature branch: git branch -d <branchname>
Push the branch to your remote repository, so others can use it: git push origin <branchname>
Push all branches to your remote repository: git push --all origin
Delete a branch on your remote repository: git push origin :<branchname>
Update from the remote repository Fetch and merge changes on the remote server to your working directory: git pull
To merge a different branch into your active branch: git merge <branchname>
View all the merge conflicts:View the conflicts against the base file:Preview changes, before merging: git diffgit diff --base <filename>
git diff <sourcebranch> <targetbranch>
After you have manually resolved any conflicts, you mark the changed file: git add <filename>
Tags You can use tagging to mark a significant changeset, such as a release: git tag 1.0.0 <commitID>
CommitId is the leading characters of the changeset ID, up to 10, but must be unique. Get the ID using: git log
Push all tags to remote repository: git push --tags origin
Undo local changes If you mess up, you can replace 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. git checkout -- <filename>
Instead, to drop all your local changes and commits, fetch the latest history from the server and point your local master branch at it, do this: git fetch origingit reset --hard origin/master
Search Search the working directory for foo(): git grep "foo()"


AngularJS Download File From Server - Best way with Java Spring Backend

Here's how you can download a file from server using AngularJS.

In this example, the client sends a API call to Java server to download a file /api/download/{id} and server sends the base64 data stream download for a given file id.

Below is the snippet from working code. The code is pretty descriptive.
This will allow you to download any type of file.

AngularJS controller method:

function downloadReportFile(fileId) {
    Download.downloadQueuedReport({id: fileId}, function (response) {

        var anchor = angular.element('<a/>');
            href: 'data:application/octet-stream;base64,' +,
            target: '_self',
            download: response.headers.filename        });



AngularJS service to do the API call:

'downloadQueuedReport': {
    method: 'GET',
    url: 'api/download/:id',
    params: {id: '@id'},
    transformResponse: function (data, headers) {
        var response = {}; = data;
        // take note of headers() call        response.headers = headers();
        return response;

Spring Powered Backend REST API 

@RequestMapping(value = "api/download/{id}",
    method = RequestMethod.GET,
 public ResponseEntity<byte[]> downloadReportFile(@PathVariable Long id) {
    log.debug("REST request to download report file");

    File file = getReportFile(id); // a method that returns file for given ID
    if (!file.exists()) { // handle FNF
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);

    try {
        FileSystemResource fileResource = new FileSystemResource(file);

        byte[] base64Bytes = Base64.encodeBase64(IOUtils.toByteArray(fileResource.getInputStream()));

        HttpHeaders headers = new HttpHeaders();
        headers.add("filename", fileResource.getFilename());

        return ResponseEntity.ok().headers(headers).body(base64Bytes);
    } catch (IOException e) {
        log.error("Failed to download file ", e);
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);


JavaCV Configuration in Windows

I had published a article on how to configure JavaCV on windows machine about 5 year back. Since then a lot of changes has been made to JavaCV:
  • The repository host Google Code stopped their services
  • JavaCV team moved to github with a different package name. They have replaced the "com.googlecode.javacv.cpp." package with "org.bytedeco.javacpp."
  • They ( probably OpenCV too) moved some classes here and there.  eg:  the static method cvSaveImage is now under org.bytedeco.javacpp.opencv_imgcodecs.cvSaveImage package. It was on com.googlecode.javacv.cpp.opencv_highgui.cvSaveImage  before.
  • Finally the good thing is the installation/setup steps has been easier than before.  This is because they have wrapped all libraries files (dll, so ) into the platform specific jar files and we don't need to install and configure the OpenCV binaries separately

Setup Steps:

1) Install the JDK on your system. 

You can choose between 3 options:
  • OpenJDK or
  • Sun JDK or

2) Download the JavaCV binaries.

2.a) Manually:
2.b) Automatically - Using Maven

3) Project Setup:

3.a) Basic project using Eclipse/Netbeans,Intellij or other IDE
Extract the JavaCV binaries and add all the jars into your classpath.

3.b) Maven Project Setup:
If you want to use Maven you need to add the dependencies as in 2.b) in your pom.xml file. There is already a sample project available on GitHub. Download it and import into  your IDE. It has a sample code to capture images from webcam.

GitHub Sample Project URL:

Sample Code to Capture Images from WebCam:

Happy Coding ...

Solve - Hyper-v not compatible on VMware player

I had enabled hyper-visor when installing docker in my system. But it seems it needs to be disabled to allow VMware run smoothly.

The error that I got from VMware.
Hyper-V not compatible - VMWare Error


Here's how I solved it:

1) Run command prompt as Administrator
2) Run the following command to disable hyper visor launcher
  C:\>bcdedit /set hypervisorlaunchtype off

If you want to enable it back to run Docker, the following command will help.
  C:\>bcdedit /set hypervisorlaunchtype auto

Java - Convert HTML to PDF File - Using iText

Here's how you can convert HTML to PDF using iText and Flying Saucer PDF libraries in Java. The steps are described within the code below.

You can easily add some methods below to read HTML content from a file and convert the HTML file to PDF ( instead of HTML string to PDF).

package g.t.test;

import org.xhtmlrenderer.pdf.ITextRenderer;

public class HtmlToPDFConverter {

    public static void convert(String htmlContent, File pdfFile) throws Exception {
        ByteArrayOutputStream os = new ByteArrayOutputStream();

        //step1: render html to memory         
        ITextRenderer renderer = new ITextRenderer();

        //step2: conver to byte array stream         
        byte[] pdfAsBytes = os.toByteArray();

        //step3: write byte array stream to file         
        FileOutputStream fos = new FileOutputStream(pdfFile);

    // let's test !! 
    public static void main(String[] args) throws Exception{
        convert("<html> <body> " +
            "<h1>Hello Crazy World !!</h1> <br/> " +
            "<h2> I hope you are doing great.</h2> " +
            "</body> </html>", new File("test.pdf"));

Used Maven Dependencies:


QC/QA/Software Testing Training Videos Free

I've listed some useful videos that would be beneficial for  beginners or some one who wants to understand software testing from scratch. These are free and best  videos that I found on YouTube.

You can watch these in sequence. The first three videos discusses the fundamental and the 4th and 5th playlist has the information in depth.

1) Open Lecture by James Bach on Software Testing


3) Software Testing Tutorial for beginners

4) Manual Testing Tutorials: 34+ videos


5)Software Testing Videos: 9+ videos

Maven use local jar without installing

You can install a local jar by using  mvn install:install-file command/goal as I discussed in my earlier blog post. This ensures the re-usability of jar file across your projects but as a drawback, this requires every team member and build server to run the same command/goal to build their project.

To avoid to the manual hassle, you can add the .jar in pom.xml file without running the mvn install:install-file goal. The idea is to refer a .jar from your project base directory using the <systemPath> element.

In example below, I put my jar files to /myjars directory and point to the jar file as
        <systemPath>${project.basedir}/myjars/[Jar file name]</systemPath>

Directory Structure




For web project (war files )

If you are working on a web project, the above configuration won't add the jars to war file by default. You need to do following.

Here we are asking maven-war-plugin to add all jar ( **/*.jar) from  ${project.basedir}/myjars  to WEB-INF/lib folder when creating the war file.


MySql get full name from last first mid name

Using CONCAT_WS to extract full name from first , middle and last name. 

It also handles the case that the mid_name can be empty or null or even have multiple spaces!

SELECT id, email,
    CASE WHEN mid_name IS NULL OR TRIM(mid_name) ='' THEN
        CONCAT_WS( " ", first_name, last_name )
        CONCAT_WS( " ", first_name, mid_name, last_name )
    END AS full_name

JPA EntityManager get Session Object in Hibernate

How to get Session object from JPA EntityManager

With Hibernate (JPA 2.0 implementation), you would do:


//1. Inject/Autowire Entity Manager
private EntityManager entityManager;    //javax.persistence.EntityManager 

//2. Get Session Object 
Session session = entityManager.unwrap(Session.class);  //org.hibernate.Session