Monday, March 14, 2016

Creating Git Repository

Today we will try to create a Git Repository in Ubuntu Server (which is a VM) and try to access the Repository from Windows.

The steps involved are as follows:

We should be having the below prerequisites for Installing Git and (Stash/BitBucket which is Optional).

Installing Java JDK 1.8 on Ubuntu:
-----------------------------
vijay@ubuntu:~$ sudo add-apt-repository ppa:webupd8team/java
vijay@ubuntu:~$ sudo apt-get update
vijay@ubuntu:~$ sudo apt-get install oracle-java8-installer
vijay@ubuntu:~$ javac -version
javac 1.8.0_74
vijay@ubuntu:~$

Installing Perl 5.5 or above:
----------------------
vijay@ubuntu:~$ apt-get install -y perl
vijay@ubuntu:~$ perl --version
This is perl 5, version 20, subversion 2 (v5.20.2) built for x86_64-linux-gnu-thread-multi


Installing git in Ubuntu:
--------------------
vijay@ubuntu:~$ sudo apt-get install -y git
vijay@ubuntu:~$ git --version
git version 2.1.4

After Installing Git we should start working with it by acknowledging it who you are with the below two commands:

git config --global user.email "chvijay.1990@gmail.com"
git config --global user.name "vijay"

now create a folder under /opt/git/ hierarchy as below:

sudo mkdir --mode=u+rwx,g+rws,o-rwx repo1.git
sudo chown vijay.gitgroup repo1.git

This will ensure that repo1.git follow some permissions for vijay the user and gitgtoup which is our group

now run the below command inside the repo1.git directory:
git init --bare

now it will have the settings of a git repository:

Now we will try to clone it somewhere else and see whether the files got updated or not:

Create a directory in home folder as below:

sudo mkdir --mode=u+rwx,g+rws,o-rwx repos
sudo chown vijay.gitgroup repos

move to the repos directory created in your home folder and clone earlier repository

git clone vijay@192.168.183.128:/opt/git/repo1.git

Now this will create a repo1 folder in repos folder:

move to repo folder and create a file named as one.txt

append some text to it and follow the below commands:

git add one.txt
git commit -am 'fix 1'
git push origin master

After testing this inside Ubuntu VM, now you can start the work with your host OS Windows, Now before working with GIT you should install it in Windows using below link:

downloadableLink

After installing this in Windows, launch command prompt and introduce your self to Git using the earlier two commands once again:

git config --global user.email "chvijay.1990@gmail.com"
git config --global user.name "vijay"

now create a directory repos in D: directory using below commands:

D:\>mkdir repos
D:\>cd repos
D:\repos>

Now Inside this directory run the below command to get the main repository cloned to this place:

git clone vijay@192.168.183.128:/opt/git/repo1.git

After running this command the repo1 folder will be created in repos directory, in the above command 192.168.183.128 is the ipAddress of the the Ubuntu VM.

Now start working with the repository using GIT shell commands.

Have a nice time and thanks for visiting our blog :-)


Monday, March 7, 2016

Working with SubShell in Linux:

When you want to make some task got forked and get the child process run as a subshell, then you can go for the below shell script which does the same for you, increase sleep time to check the execution status of the child process with the command "ps -ef | grep sub" in one more terminal:

#!/bin/bash
while :
do
echo "[ hit CTRL+C to stop]"
echo Enter Command to Process:;
read cmd;
echo $cmd > tmp2;
(sleep 3;bash -s <tmp2 );
done