Friday, June 16, 2017

GitHub - Some basic info including branch

Github instructions.

First create an account in github

Create a repository:

Use the '+' icon on the top right corner.

For example create a repository named 'my-project'

Add some description to repository description input box.

Choose public repository as repository type.

Tick 'Initialize this repository with a README'

Now you just finished creating your first repository.

Clone the Repository to your local machine:

On the repository page we can see a green Clone or download  button. Click it and you will see the url of your repository.. Copy it.

Open the Terminal (Command Prompt).

I hope you have already installed git. Otherwise install git. After that, do the following:

On the command prompt execute the command:

git clone <the url you copied>

For eg: git clone

This will create a folder in the present directory named 'my-project'

You can open it and see the files in it.. It consists of a file and a hidden .git folder.

Updating your changes to git repository

Create a file named sample.txt in the my-project folder and add some text in it.

Take the terminal and just change the working directory to 'my-project'. For it execute the following command:

cd my-project

After it run the following command:

git status

It will show the below result
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)


nothing added to commit but untracked files present (use "git add" to track)

Now execute the below command :

git add sample.txt 

It is adding the file to git index.

Then the next command:

git commit -m 'first commit'

Then the next command:

git push origin master

Now it will ask for your username and password of git, paste it and now you just finished your first commit to the git repository.

Now check your git repository and you can see the new file 'sample.txt' there..

Just check out the insights->graphs->network You can see a graphical representation of the commits. It will be very helpful when having many branches.

Create Branch

We can create branch in github or in terminal. 

For now just create a new branch in github.

For it click on the dropdown 'Branch:master' and type the new branch name in the input box 'first-branch' and hit enter. it will create a branch.

Then open the terminal and type the command 

git pull

It will show the new branch there

For working with the new branch run the following command:

git checkout first-branch

It will show the message like 'Switched to a new branch 'first-branch''

Then create another file sample2.txt and add some content to it.

Then take the terminal and run the command:

git status

It will show the new file sample2.txt there and commit it as we done early:

git add sample2.txt 

git commit -m 'test'

git push origin first-branch

After committing the sample2.txt check the git repository and insights->graphs->network. We can see the new branch there.

Create Pull Request and Merge it to master:

I hope in the repository now you can see the button 'Compare & Pull Request'. Click on it and the  following page click on 'Create Pull Request' and on the following page 'Merge Pull Request'. then 'Confirm Merge'. Now the new branch is merged with the master branch.

Now check the graph and we can see the new branch merged with the master branch.

Take the terminal and run the below command:

git pull

As the current branch 'first-branch' it is uptodate

Now change the branch to master.

For it run the command

git checkout master

Now open the 'My project' folder and we can see it is missing the second file we created in the first branch' So we need to update the branch.. for it again git pull from terminal...

Now I hope you get the basic ideas... check some more tutorials and you will get more ideas..

Git commands I used :

  git clone
  945  ls
  946  cd sample_repo/
  947  ls
  948  git status
  949  git add sample.txt
  950  git status
  951  git commit -m "sample file added"
  952  git status
  953  git push
  954  git status
  955  git pull
  956  git checkout add-name
  957  git status
  958  cd ..
  959  git status
  960  cd sample_repo/
  961  git branches
  962  git --help
  963  git branch
  964  git checkout master
  965  git branch
  966  git checkout add-name
  967  git status
  968  git add sample.txt
  969  git status
  970  git commit -m 'added name'
  971  git status
  972  git push
  973  git pull
  974  git checkout master
  975  git status
  976  git pull
  977  git checkout master
  978  git status
  979  git add sample.txt
  980  git commit -m 'house name added'
  981  git push
  982  git checkout add-name
  983  git pull
  984  git checkout master
  985  git pull
  986  git checkout add-name
  987  git status
  988  git remote -v
  989  git status
  990  git checkout -b family
  991  git status
  992  git add sample.txt
  993  git commit -m 'added count of family members'
  994  git push
  995  git push --set-upstream origin family
  996  git checkout master
  997  git checkout -b father
  998  git status
  999  git add sample.txt
 1000  git commit -m 'father name added'
 1001  git push origin father
 1002  git checkout family
 1003  git status
 1004  git pull
 1005  git checkout master
 1006  git pull
 1007  git checkout family
 1008  git branch
 1009  git merge master
 1010  git status
 1011  git add sample.txt
 1012  git -m 'merged manually'
 1013  git commit -m 'merged manually'
 1014  git status
 1015  git push
 1016  git merge father
 1017  git checkout family
 1018  git reset --hard 9742e
 1019  git status
 1020  git add
 1021  git add *
 1022  git status
 1023  git commit -m 'added hello'
 1024  git push
 1025  git pull
 1026  git status
 1027  git checkout father
 1028  git pull
 1029  git branch
 1030  git branch --set-upstream-to=origin/father
 1031  git pull
 1032  git diff master father
 1033  git merge master
 1034  git branch
 1035  git checkout master
 1036  git pull
 1037  git checkout father
 1038  git merge master
 1039  git status
 1040  git git add sample.txt
 1041  git add sample.txt
 1042  git commit -m 'merged'
 1043  git push origin father
 1044  git chekout master
 1045  git checkout master
 1046  git status
 1047  git pull
 1048  git merge father
 1049  git status
 1050  git push origin master
 1051  git status
 1052  cd ..
 1053  cd gittest/
 1054  git init
 1055  git status
 1056  git add test.txt
 1057  git commit -m 'test added'
 1058  git push origin master
 1059  git remote add origin
 1060  git push origin master

Thursday, January 5, 2017

Starting with Node Js

Installing node.js in Virtual Machine.

After running the virtual machine, ssh to it.

I am using the NVM(Node Version Manager) to install the node. So we can install the version we want.

Anyway I have just installed the latest version.

First we need to install the NVM.

So take the terminal and follow the steps in the below link.

so after installing nvm we can install the desired node js version

I have installed the latest version  by using the below command

nvm install node

for more info about installing node check the below link:

After restarting the terminal if you see any error when running the command 'node' from the terminal like the following :

"The program 'node' can be found in the following packages:
 * node
 * nodejs
Try: apt-get install <selected package>"

then use the command : nvm use node

As I am using Virtual machine I need to update the server code slightly to get the node run in the main browser that is not in virtual machine

I have created the server using the below code.. check the listen section, where I put the IP address of the virtual machine.

var http = require("http");

http.createServer(function (request, response) {

   // Send the HTTP header 
   // HTTP Status: 200 : OK
   // Content Type: text/plain
   response.writeHead(200, {'Content-Type': 'text/plain'});
   // Send the response body as "Hello World"
   response.end('Hello World\n');
}).listen(8081, '');

// Console will print the message

console.log('Server running at');

Now you can start develop your own code..