Category: Raspbian

Home / Category: Raspbian

What is Git

Git is a version control system (VCS) that is used for software development and other version control tasks. As a distributed revision control system it is aimed at speed, data integrity, and support for distributed, non-linear workflows.

Git was created by Linus Torvalds in 2005 for the development of the Linux kernel, with other kernel developers contributing to its initial development. Its current maintainer is Junio Hamano.

Run your own Git server

Git manages the version control of applications and there are many git repositories. All git repositories which are free is having some limitations.

GitHub is one of the great services but we can’t create private repository in  GitHub free . For Private repo, you have to pay minimum 7$ per month, and the expenses go up with more repos.

In cases you don’t want to pay any extra for version control then the best is to create your own Git server. Not only do you save costs, you also have more control over your server.

Install Git on your server

In this installation methods, we are going to use two host machines one for the server (Linux) where we are going to make our repository and another the local machine through which we are going to connect the git server so let start .

Step1 : Install Git In both machine

Server Machine:


sudo yum install git
sudo apt-get install git

Local Machine :

Linux  :

sudo yum install git
sudo apt-get install git

Windows :

Visit and download the latest version for your windows

Step2 : Install Git-core In server

sudo yum install git-all
sudo apt-get install git-core

Step3 : Create user : git

sudo useradd git
passwd git

Step4 : Create SSH Key for local Linux machine (Optional)

Create ssh keys on your local machine to avoid asking password only for Linux Based Local System:

ssh-keygen -t rsa

leave all as default by press Enter and save it in a secure location .

Now you have to copy these keys to the server so that the two machines can talk to each other. Run the following command on your local machine:

cat ~/.ssh/ | ssh [email protected] "mkdir -p ~/.ssh && cat >>  ~/.ssh/authorized_keys"

Step5 : Create a repository

Create a directory on your server machine and remember this will be your repository URL

[email protected]:~ $ mkdir -p /home/git/repo-name.git

Then change to this directory:

cd /home/git/repo-name.git

Then create an empty repo:

git init --bare
Initialized empty Git repository in /home/git/repo-name.git

Step6 : Create a Git repo in local machine

Linux users can use Terminal and windows users should us GIT BASH

mkdir -p /home/ramith/Desktop/Arduino

And change to this directory:

cd /home/ramith/Desktop/Arduino

Now create the files that you need for the project in this directory.

git init 
Initialized empty Git repository in /home/ramith/Desktop/Arduino

Now add files to the repo:

git add .

Now write your commit message

git commit -m "First Commit" -a
[master (root-commit) 57331ee] message
 1 files changed, 1 insertions(+)
 create mode 100644 script.txt

Till now you were working on the local machines repo.Now we need to push this to our git server so that team can collaborate. To do this we need to push this to the remote location in our Git Server. To add the location need to type below command

git remote add origin ssh://[email protected]/home/git/repo-name.git

Now you can push or pull changes between the server and local machine using the ‘push’ or ‘pull’ option:

git push origin master

Step7 :Cloning the repo with local machine

If there are other team members who want to work with the project they need to clone the repo from the server to their local machine:

git clone [email protected]:/home/git/repo-name.git

Then change directory on the local machine (exchange project with the name of the project on your server):

cd /repo-name

Now they can edit files, write commit change messages and then push them to the server:

git commit -m 'Second Commit Edited in script.txt' -a

And then push changes:

git push origin master


The Raspberry Pi’s very existence can be chalked up to creativity.  Raspberry Pi Foundation created the $35 Single Board Computer to inspire students to learn computer science and play with programs.

Raspberry help you to connect with various I/O Devices (Sensors,Lights,motors,etc..) using 40 Pin GPIO Ports.This help users to make a gateway between computer programming and electronic devices. You can control this ports using Python directly.


It’s a programming language which help raspberry to connect the raspberry GPIO Pin to switch it ON and OFF. Python is simple and easy to learn and it’s totally dependent on indentation.


#!/usr/bin/env python
import RPi.GPIO as GPIO
import sys, getopt

def gpio(pin):
    pin = int(pin)
    switcher = {
        2: 3,3: 5,4: 7,5: 29,6: 31,7: 26,8: 24,9: 21,10: 19,11: 23,12: 32,13: 33,14: 8,15: 10,16: 36,17: 11,18: 12,19: 35,20: 38,21: 40,22: 15,23: 16,24: 18,25: 22,26: 37,27: 13,
    return switcher.get(pin, "false")

def main(argv):
    gpiopin = ''
    status = ''
    type = 'pin'
        opts, args = getopt.getopt(argv,"hg:s:t:",["gpio=","status=","type="])
    except getopt.GetoptError:
        print ' -g  -s  -t <pin/gpio>'
    for opt, arg in opts:
        if opt == '-h':
            print ' -g  -s  -t <pin/gpio>'
        elif opt in ("-g", "--gpio"):
            gpiopin = arg
        elif opt in ("-s", "--status"):
            status = arg
        elif opt in ("-t", "--type"):
            type = arg
    if gpiopin != "":
        if type=='gpio':
        GPIO.setup(gpiopin, GPIO.OUT)
        if status == 0:
        print ' -g  -s  -t <pin/gpio>'
if __name__ == "__main__":

How to execute

sudo python -g <pin number> -s < 0(off) / 1(on) > -t <pin/gpio>


sudo python -g 19  -s 0 -t gpio

PIR infrared sensor module is based on infrared technology, automatic control products. High sensitivity, high reliability, low power consumption, low voltage operation mode. Widely used in various auto-sensing electrical equipment, especially for battery-powered automatic control products.

Using PIR we can identify the motion and this sensor will transmit a signal for 3 sec so we need to do a program and detect the motion and as per your requirement you can activate or deactivate any functions like switching on camera when motion is detected.

I am going to use Raspberry Pi 2 For this small Project . In this Project i am designing and program to detect a motion and on basis of that alarm will be played for 1 minute.

Requirement :

1.Raspberry Pi

2.Pyroelectric Infrared Pir Motion Sensor Detector Module

3.Computer With Putty Installed


Step 1.

Install any raspberry based Operating system with GPIO Package installed and as well as Python Installed. I am using OSMC.

Step 2.

Connect the PIR VCC,OUT,GND to Raspberry pi 5v,GPIO4,GND


VCC – > 5v
OUT -> GPIO4 (Pin 7)


Step 3

Connect to raspberry pi using SSH (Putty For Windows)


Create a python program and copy bellow code .And after saving run the script with sudo permission

import RPi.GPIO as GPIO
import time
import os
#GPIO Pin number where the sensor out is connected
while True:
    if sensor_input == 1 :
		#Timer in seconds for activation
        timer = 60
    if timer > 0 :
        timer = timer - 1
        print "De-activating in :",timer,"secs"
        if switch_on!=1 :
            #If you want to output using 26 GPIO Remove below 2 lines comment
            #GPIO.setup(26, GPIO.OUT) 
            print "--- Switch Activated ---"
        if switch_on!=0 :
            print "Switch Deactivated"
            #If you want to output using 26 GPIO Remove below 2 lines comment
            #GPIO.setup(26, GPIO.OUT)