Tuesday, July 7, 2015

When to use Git rebasing and why ?

note : My earlier post was about some of the useful commands of git and how to use them

Git rebase : introduction


Git rebase is a handy mechanism when you need merge the changes of your branch with another branch (probably with the master branch) . But the process behind a git-rebase is not that simple as the definition suggests , but it is clean and awesome . In this post , I am going to go through with the process behind a git rebase , when to use it , and when to avoid it .

Let's look at the following simple scenario..

Say you have a master branch called master .. (duh)

And you are creating a development-branch out of this master branch to do your development stuff.



And you are now working on this development-branch for sometime . You make changes , you add these changes and you commit those changes to this branch . Now after few days , you decides that it is the right time to integrate your changes to the master branch . But guess what , your team members have already pushed their changes to the master branch . So you cannot just easily merge your changes to the master without messing up the changes of your peers . Following diagram illustrates the situation



As you can see there is a gap between the branch you are working on and the master . This is where the it rebase comes in .By using git rebase you are going to integrate your changes (commit B1 , B2) with the master (Where now the head is located at commit M3) , 





Now the situation changes to something like below



                                    

When you use git rebase , the commit history (commit hashes) changes entirely . That is why i have used the green color to represent the history instead of blue (color of master's commits) or red (color of development-branch commits).

The Advantage 


It creates a linear History which is the very reason why we need to use git rebasing. Your history is clean flat and readable . You can identify the commits of each of your team members very easily in different timelines .


The Disadvantage

In a situation where you have so many people consistently pushing their changes to master and when there are so many branches being merged with the master , It is kind of a pain in the a** to keep your branch upto date with master using git rebase . You have to constantly do the rebasing , and might need to resolve conflicts time to time 

Also rewriting your commit history after each and every reabsing is not always a good thing . It means that your commit hashes change consistently and also , you need to force push every time to the remote after a rebase

When to use git rebase : Only when you need a clean linear history so that you can clearly see what is going on with the all the commits from all the team members


When not to use : If you prefer to follow a simple mechanism where you can integrate your changes with the upstream branch without a fuss you can always go with git merge 



Saturday, June 27, 2015

Useful git commands

Lets have a look at some of the useful git commands 


Get a clone of the remote repository

  • git clone <remote repository link>

Get a pull from the remote branch

  • git pull <remote branch name>

Get a pull from the remote branch and rebase the remote branch with the local branch

  • git pull --rebase origin <branch name>

Get all the branches from the remote repository 

  • git fetch --all


Push the changes to remote

  • git push origin <branch-name>
  • git push origin <branch-name> --force #force push the changes


Checkout a branch

  • git checkout <branch name>

Checkout a new branch from the current branch

  • git checkout -b <branch name>

Add a file to commit

  • git add  <filename> #Adds 1 file
  • git add --all #Adds all the files including tracked and un-tracked files

Commit with a message

  • git commit -m "message name"

Stash the current changes and make branch pristine

  • git stash

Un-stash the last changes which were stashed ( hence make the branch dirty)

  • git stash apply

Delete branch


  • git push :<branchname> # delete remote branch name
  • git branch -d <branchname> #delete local branch name
  • git branch -D<branchname>#force delete local branch name 


Change the last commit message 

  • git commit --amend -m "New commit message"


Change remote branch name 

  • git branch <new-branch-name> <origin old-branch-name> #change remote branch name with the new name
  • git push origin <new-branch-name> #push the new branch with the new name
  • git push origin :<old-branch-name> #delete the old branch branch
  • git push -D <old-branch-name>


Change local branch name

  • git branch -m <old-branch-name> <new-branch-name> #If you want to rename any branch
  • git branch -m <new-branch-name> #If you want to change the current branch


Reset last commit 


  • git reset --hard HEAD~1
  • git push origin <branch-name> --force # This step will push the reverted changes back to the remote


Reset last commit but keep the changes in local branch

  • git reset HEAD~1


Rebase your current branch changes with the local master branch

  • git rebase origin/master


Merge your changes with the master branch

  • git merge <branch-name> --no-ff  #Creates a commit for merge and does the merge with fast-forward mechanism


Get git commit history in a compact way

  • git log oneline

Friday, June 26, 2015

Git rebase merge conflict solving : Did you forget to use add ?

Sometimes when you rebase your branch with the master branch and after fixing a merge conflict you might encounter following issue


The loopy problem of git rebasing



$ git rebase –continue

Applying: loglevel equal to silent
No changes – did you forget to use ‘git add’?
If there is nothing left to stage, chances are that something else
already introduced the same changes; you might want to skip this patch.


When you have resolved this problem, run “git rebase –continue”.
If you prefer to skip this patch, run “git rebase –skip” instead.
To check out the original branch and stop rebasing, run “git rebase –abort”
.










But the problem you might having is that you have already added the file using git add <yourconfilctedfilename>  And might have added several times but still Git telling you to add the file again ??

Sometimes you got to skip your problems , bro

I have encountered this issue couple of times and it turns out is a Git bug which was later fixed with Git 2.0.2 version. So anyway in this case rather than updating your git application , you can simply do ..

git rebase –skip 

and just skip the patch. It will not do any harm because the patch was empty anyway ! 

How to set Visual Studio Version With NPM

When you install NPM modules in windows environment  , some times you might ran into an error like below.

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets(64,5): error MSB8020: The build t
ools for Visual Studio 2010 (Platform Toolset = ‘v100′) cannot be found. To build using the v100 build tools, please in
stall Visual Studio 2010 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting t
he Project menu or right-click the solution, and then selecting “Upgrade Solution…”. [C:\Users\Documents\FLIS.Client.Tests\
node_modules\karma\node_modules\socket.io\node_modules\socket.io-client\node_modules\ws\build\bufferutil.vcxproj]

As you can see the error says that it cannot find the Visual studio 2010 platform toolset. In a scenario like this you can externally specify build platform toolset to NPM like this.

–msvs-version=2013 // I am running visual studio 2013 . So…

Say For E.g If you want to install protractor with –msvs-version=2013 

npm install protractor –msvs-version=2013

Difference between $scope and $rootscope

This article is written assuming you have the basic concepts of AngularJS !


Whenever you declare a controller in angular , you automatically create a $scope . So what does a $scope mean : “$scope is an object that refers to the application model. It is an execution context for expressions. $scopes are arranged in hierarchical structure which mimic the DOM structure of the application. $scope can watch expressions and propagate events.” documentation .

In simpler terms it means that it is a way of tying an object to the DOM . If you consider the MVC model in Angular , the scope acts as a model . It is a template which hosts all the functions and the related data . 

Okay now that we have gotten some insight into the $scope , let talk about $rootscope shall we ? $rootscope is the parent (more like a root parent ) of all the $scopes you create . It is the ultimate boss . It is (almost) like the Object class of Java .It is the top most $scope of your app and it contains ng-app directive . There is only one $rootscope for each of the Angular application .


Friday, August 8, 2014

Some photos from my trip to Udawalawa








All images are copyrighted © Salim Malik.

Why doesn't sometimes the HR call you and say that you are rejected !





HR makes a list of people to interview. And they're not good at it. They think they're looking for a list of skills you already have. Yeah, not really. They want a checkbox, and it just doesn't work that way, most of the time. ...anyway...

Managers sometimes get the budget to hire someone, so they start looking at the list of resumes. They put a few of them in order, and ask HR to set things up.

Things go well enough to interview on site, in person. So, that happens.

Then everyone who interviewed you sits in a room, and talks about you. HR and the hiring manager ask a few questions.

And a decision is made.

The decision is one of several things:


We'd like to make an offer
This is one of the better candidates
This person might be interesting some day
Might be a better fit for a different team
No



Here's where your confusion comes in

The only one of those where HR feels that time is critical is "We'd like to make an offer."

In all of those other scenarios, HR feels no pressure to get back to you.

If you believe you're in the "This is one of the better candidates" category, you can try to speed up the process by telling HR that you're "considering other offers." Sound remorseful about it. The tone is, yeah, I'd like to work with you, but I have an offer on the table that's expiring, and I need to give them an answer. Note that if you're not in the "This is one of the better candidates" category, this won't help you at all.

One more thing

There's only one category where the company has decided to never hire you, and that's "No".

For ALL of the other categories, the company is still thinking to themselves that maybe they might offer you a job, some day, if they grow large enough, and your skills match what they need, and other candidates haven't accepted the offer.

I work with a couple people who got their offers 12 months after they interviewed. The timing happened to be right, and they were looking, so they accepted.

But it's never worth it to the company to tell you "no." It's not worth the time to pay the HR people to send you the letter, or call you. What if they called the wrong person? Or misunderstood and said "no" when they shouldn't have? There's just no value to them in telling you no.

Especially since your next question is going to be "why not," and there's no way they're going to honestly answer that. Too much legal liability.

So, if you ever get a "no" call from HR, it's because they're being super polite.

Don't ever expect a "no" call.