Thursday, April 20, 2017

Git (Quick Commands)

Configure Git for the first time
git config --global "Manglick, Arun"
git config --global ""

Working with your repository
I just want to clone this repository
Simply clone this empty repository then run this command in your terminal.
git clone

Note: Clone command implicitly adds the origin remote for you.I.e.
You need not to add git remote add origin if clone is already used.
Clone Code:
 From the repository in Bitbucket, click the Clone button & Copy Clone Path
 cd local-directory
 $ git clone ssh://

Clone Specific Branch:
 git clone -b
 git clone -b master
 git clone -b onsite_branch
Push Code:
cd existing-project
git init
git status [-s]
git add --all
git add
git status

 $ git status -s
M README - Modified files have an M
A lib/git.rb  - After added to the staging area (After Commit)
?? LICENSE.txt - New files that aren’t tracked have a ?? next to them,

 Unstaging: Files are staged using above git add command.
To unstage a file (to remove a file or files from the staging area):
- git rm --cached  OR
- git reset  
- git reset --hard origin/branch_to_overwrite

git reset did a great job of unstaging octodog.txt, but you'll notice that he's still there.
Files can be changed back to how they were at the last commit by using the command:
git checkout --
git checkout -- octocat.txt

 Commit Staged Files as below:
git commit -m "Initial Commit"

 --  So far local repo is created. Now to push our local repo to the GitHub server, we'll need to add a remote repo on GitHub
(This command takes a remote repo name (e.g. origin) and a repository URL (e.g.
(Git doesn't care what you name your remotes, but it's typical to name your main one origin)
git remote add
git remote add origin

 -- Now finally push our local changes to our remote repo...origin in our case.
(The name of our remote is origin and the default local branch name is master)
(The -u tells Git to remember the parameters, so that next time we can simply run git push and Git will know what to do)
git push -u origin master
My code is already tracked by Git
If code is already tracked by Git then set this repository as your "origin" to push to.
cd existing-project
git remote set-url origin
git remote set-url origin
git remote set-url origin

 git push -u origin master
Pull Code:
 cd existing-project
git pull
cd existing-project
git pull origin master

-- Sometimes when you go to pull you may have changes you don't want to commit just yet.
One option you have, other than commiting, is to stash the changes.
Use 'git stash' to stash your changes, and
Use 'git stash apply' to re-apply your changes after your pull.

Use 'git stash drop' with the name of the stash to remove.
Also you can run 'git stash pop' to apply the stash and then immediately drop it from your stack.

 git checkout -- octocat.txt
 There is a possiblity that three some additions and changes to repo family.
 Let's take a look at what is different from our last commit by using the git diff command.
 In this case we want the diff of our most recent commit, which we can refer to using the HEAD pointer.
 (The HEAD is a pointer that holds your position within all your different commits. By default HEAD points to your most recent commit,)
 git diff HEAD  OR
 git diff --staged

Staged Differences
 Another great use for diff is looking at changes within files that have already been staged.
 Remember, staged files are files we have told git that are ready to be committed.

  git diff  -- That command compares what is in your working directory with what is in your staging area.
  git diff --staged  -- This command compares your staged changes to your last commit

Branching Out
(When developers are working on a feature or bug they'll often create a copy (aka. branch) of their code they can make separate commits to. Then when they're done they can merge this branch back into their main master branch nd push it to the remote server)
- git branch Branch_Apr

Great! Now if you type git branch you'll see two local branches: a main branch named master and your new branch named  Branch_Apr
- git branch

(Switch between branches)
- git checkout

(Perform both things in one command)
- git checkout -b Branch_Apr
(Notice the phrase “fast-forward” in that merge)

(To check HEAD is pointing to which branch)
- git log --oneline --decorate

(To see the last commit on each branch)
- git branch -v

(To see which branches are already merged into the branch you’re on)
git branch --merged
* master

(Pg 99- Because you already merged in Branch_Apr earlier, you see it in your list.
Branches on this list without the * in front of them are generally fine to delete with git branch -d;
As you’ve already incorporated their work into another branch, so you’re not going to lose anything)

(To see which branches are not merged into the branch you’re on)
git branch --no-merged
* master

(To add branches created by someone else and you are not able to see those branches in your list)
$ git remote update
$ git branch -r
Preparing to Merge
 Switching Back to master
 - git checkout master

We're already on the master branch, so we just need to tell Git to merge the Branch_Apr branch into it:
- git merge Branch_Apr

Merging Issues: Two Ways:
- Manual -
 - Manually Resolve those conflicts and (Pg -97 ProGit Book)
 - Then run "git add"" on each file to mark it as resolved.Staging the file marks it as resolved in Git.
- Graphically - Use git mergetool
- Finally after merge issue resolved - type "git commit" to finalize the merge commit
- One more Finally - git push origin to finally push merged changes to git

- Merging specific file)(s) between branches (Brutal Force Merge)
Assume you are in master branch and want to merge from dev_i3 branch, use this syntax:--
git checkout .     (To Merge Entire Branch content)
git checkout
git checkout dev_i3 views/shared/nav.cshtml
(Ref Link:

- Merging specific file)(s) between branches
$ git checkout --patch branch2
The interactive mode section in the man page for git-add(1) explains the keys that are to be used:

y - apply this hunk to index and worktree
n - do not apply this hunk to index and worktree
q - quit; do not apply this hunk or any of the remaining ones
a - apply this hunk and all later hunks in the file
d - do not apply this hunk or any of the later hunks in the file
g - select a hunk to go to
/ - search for a hunk matching the given regex
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk
k - leave this hunk undecided, see previous undecided hunk
K - leave this hunk undecided, see previous hunk
s - split the current hunk into smaller hunks
e - manually edit the current hunk
? - print help
Delete Branch (After Merge in Master)
 git branch -d to delete a branch.

Force delete
 - What if you have been working on a feature branch and you decide you really don't want this feature anymore?
 - You might decide to delete the branch since you're scrapping the idea.
 - You'll notice that git branch -d doesn't work.
 - This is because -d won't let you delete something that hasn't been merged.
 - You can either add the --force (-f) option or use -D which combines -d -f together into one command.
Check Commit Summary:
git log (To check commit history) OR
git log --summary

Showing Your Remotes
git remote -v

Inspecting a Remote
git remote show origin

Removing and Renaming Remotes
git remote rm origin
git remote rename origin myorigin

Git Differences Tool:
git difftool branch1 branch2
git difftool branch1:file1 branch2:file1
git diff --name-status branch1..branch2

Git Stages:
 - A place where we can group files together before we "commit" them to Git.
 - Files are staged using command: git add
 - To unstage a file (to remove a file or files from the staging area):
 - git rm --cached  OR
 - git reset

 - Files with changes that have not been prepared to be committed.

 - Files aren't tracked by Git yet. This usually indicates a newly created file.

 - File has been deleted and is waiting to be removed from Git.

Hope this helps.

Arun Manglick

Sunday, April 2, 2017


Posted earlier long back in 2014 … Why REST -
Here again an attempt to find buzz question REST vs SOAP .. J 
Before this, understand REST underlying concepts: 

REST Concepts are referred to as Resources.
  • Resources are manipulated by Components.
  • Components, request and manipulate Resources via a Standard Uniform Interface.
  • In case of HTTP, this interface consists of standard HTTP ops e.g. GET, PUT, POST, DELETE.
REST vs SOAP is not the right question to ask. SOAP is a protocol. REST is an architectural style.

SOAP stands for Simple Object Access Protocol
REST stands for Representational State Transfer.

SOAP is a protocol.
REST is an architectural style.
SOAP transport protocol is HTTP only
REST is protocol independent. It's not coupled to HTTP. Pretty much like you can follow an ftp link on a website, a REST application can use any protocol for which there is an standardized URI scheme.

However REST is optimized for the web, due to its support for JSON, hence incredible popularity of REST over HTTP!
SOAP uses services interfaces to expose the business logic.

SOAP is focused on accessing named operations, each implement some business logic through different interfaces.
REST uses Consistent/Standard URI to expose business logic. In case of HTTP, this interface consists of standard HTTP ops e.g. GET, PUT, POST, DELETE

REST is focused on accessing named resources through a Standard Uniform/Consistent Resource Interface.

SOAP defines standards to be strictly followed.

REST does not define too much standards like SOAP
SOAP defines its own security. e.g. WS-Security, WS-AtomicTransaction, WS-ReliableMessaging etd.

RESTful web services inherits security measures from the underlying transport.
SOAP requires more bandwidth and resource than REST (Due XML Based)
REST requires less bandwidth and resource than SOAP
(Due JSON Based)
SOAP permits XML data format only
REST permits different data format such as Plain text, HTML, XML, JSON etc
SOAP based reads cannot be cached.
REST has better performance and scalability. REST reads can be cached.
SOAP can't use REST because SOAP is a protocol.

REST can use SOAP web services because it is a concept and can use any protocol like HTTP, SOAP.

SOAP is less preferred than REST
REST more preferred than SOAP.

Fundamental REST Principles:
  • Client-Server Communication
    • Client-server architectures have a very distinct separation of concerns.
    • All applications built in the RESTful style must also be client-server in principle. 
  • Stateless
    • Each client request to the server requires that its state be fully represented.
    • The server must be able to completely understand the client request without using any server context or server session state.
    • It follows that all state must be kept on the client. 
  • Cacheable
    • Cache constraints may be used, thus enabling response data to be marked as cacheable or not-cacheable.
    • Any data marked as cacheable may be reused as the response to the same subsequent request. 
  • Uniform Interface
    • All components must interact through a single uniform interface.
    • Because all component interaction occurs via this interface, interaction with different services is very simple.
    • The interface is the same! This also means that implementation changes can be made in isolation.
    • Such changes, will not affect fundamental component interaction because the uniform interface is always unchanged. 

Hope this helps.

Arun Manglick