GIT TUTORIAL
############
############

Note: the ssh server on www.gitserver1.com is on port 50505 not 22, so if you have port 22 just leave out the part that says ‘-p 50505’

GOOD CHEAT SHEETS:
http://byte.kde.org/~zrusin/git/git-cheat-sheet-medium.png
http://www.git-tower.com/blog/git-cheat-sheet-detail/
AFTER THIS I WILL LINK TO MY GIT WEBSERVER TUTORIAL ON HOW TO SETUP cgit:
http://www.infotinks.com/linux—cgit—how-to-install-cgit-on-gitserver

MAKING THE SERVER
#################

(PC: DEBIKOS) SETUP GIT SERVER (gitserver or www.gitserver1.com):
########################################################

sudo -i

apt-get update
apt-get install git
apt-get install git-core

adduser git

It will ask for fullname,address, all are optional… The password is important, write it down, remember it (I chose $PASSWORD)

cd ~

mkdir .ssh

ADDING PROGRAMMER KEY TO GIT
############################

(PC: KNAS312) GO TO COMPUTER THAT WILL BE GIT CLIENT (a programmers computer)
#############################################################################

Copy their public key over to authorized keys on gitserver

cd ~/.ssh/id_rsa.pub | ssh -p 50505 root@www.gitserver1.com “cat – >> /home/git/.ssh/authorized_keys”

It will ask for the password that you chose during “adduser git”
To test public key: ‘ssh git@www.gitserver1.com -p 50505’ for now because git users shell is /bin/bash you will get a prompt, but in the future we will secure this user down by giving him git-shell instead of bash, the git-shell will not give a prompt but will just say something

STARTING PROJECT
################

(PC: DEBIKOS) BACK TO GIT SERVER
################################
Lets make the folder where the git projects will be saved, opt is an okay place.

# cd /opt/
# mkdir git
# chown -R git:git /opt/git
# cd /opt/git

NOTE: my first project is called hr (The app name is ‘hr’, or ‘human readable’)

# mkdir hr

# cd /opt/git/hr

Everytime you want to start a new project, go into the folder:
# git –bare init

FIRST COMMIT
#############

(PC: KNAS312) GO TO COMPUTER THAT WILL BE GIT CLIENT (a programmers computer)
#############################################################################

On this PC the ‘hr’ program is in /root/c/hr – programmers can store their programs where ever they want

cd /root/c/hr

NOTE: even if you have files there its okay to do this, you will keep your files, the git init will make some hidden git folder that store all of git information

git init

CONFIGURE USERNAME AND EMAIL
============================

By default it uses the username and email on the user on this PC

git config –global user.email “boss@infotinks.com”
git config –global user.name “infotinks”
FIRST COMMIT
============

git add .
git commit -m ‘initial commit’

PUSH IT TO SERVER
=================

First we need to setup the server and call it the origin

GENERAL FORM
# git remote add origin git@gitserver:/opt/git/project.git
Note: project.git is a folder which has all of the project

MY FORM (this is the form that is required if your ssh doesnt use the typical port 22)
# git remote add origin ssh://git@www.gitserver1.com:50505/opt/git/hr

HOW TO SUBMIT CHANGES FROM NOW ON
=================================

git add .
git commit -m ‘some comment such as did this and that’
git push origin master

(ON: ANOTHER DEVS PC) GETTING THE WORK
########################################

First add the public key over
cd ~/.ssh/id_rsa.pub | ssh -p 50505 root@www.gitserver1.com “cat – >> /home/git/.ssh/authorized_keys”

mkdir -p /root/work
cd /root/work

git clone@gitserver:/opt/git/project.git
git clone ssh://git@www.gitserver1.com:50505/opt/git/hr
(ON: DEBIKOS) ON THE GITSERVER LETS SECURE GIT
###############################################

# su root

find out where your git-shell is

# which git-shell

it should be at ‘/usr/bin/git-shell’

# vim /etc/passwd

change
‘git:x:1000:1000::/home/git:/bin/sh’

or
‘git:x:1000:1000::/home/git:/bin/bash’

to:
‘git:x:1000:1000::/home/git:/usr/bin/git-shell’
Now when you try to log in via an ssh prompt with git user you will not get a shell:

For example with a typical server
$ ssh git@gitserver

or in my case

# ssh git@www.gitserver1.com -p 50505

OUPTUT:
fatal: What do you think I am? A shell?
Connection to gitserver closed.
NEXT: WANT TO SETUP cgit?
##########################

This is for web interface for your git

cgit article here

Leave a Reply

Your email address will not be published. Required fields are marked *