Friday, September 13, 2013

Git CookBook.

Dipankar's Git CookBook
--------
Q1. How to setting up GIT server ?

IN SERVER MACHINE DO THE FOLLOWING AND CREATE REPO (ONE TIME)

$ sudo adduser git
$ su git
$ cd
$ mkdir .ssh
cd ~/.ssh
ls
# Lists the files in your .ssh directory
git@dipankar-OptiPlex-390:~/.ssh$ ssh-keygen -t rsa -C "dutta.dipankar08@gmail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/git/.ssh/id_rsa): <Enter>
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/git/.ssh/id_rsa.
Your public key has been saved in /home/git/.ssh/id_rsa.pub.
The key fingerprint is:
68:b7:df:bc:78:15:84:e9:87:b2:da:75:26:b3:38:08 dutta.dipankar08@gmail.com
The key's randomart image is:
+--[ RSA 2048]----+
|             o   |
|            o .  |
|           . o   |
|       .  . o o  |
|      o S  o . . |
|     .E. .. + +  |
|       ..+ o B   |
|        o.++o    |
|          oo+.   |
+-----------------+
git@dipankar-OptiPlex-390:~/.ssh$ 
git@dipankar-OptiPlex-390:~/.ssh$ cat dipankar.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDq1iZ9XsfJdwECXSP6i4v5gRJIvtQh8M+udJAgcPiq+Hw7Kbz2cz14rkIG6lD0yOCJpKop8FeS9Z1CDNpZDafTgPYZmi6erIygh8Mwe/BHkp8hHzrg7u1nuEqq2UX6+MLMJB7gyhdqd9/mydDRPVtgAlmyejOOlgNRUpSuSBIa4AURslmeFbFfdLbDB0iLJhFU/rtJGYCBQckLdnQG+MsCv0pK3367eLkeCQR5sGoXvbUtgxpDiCJ4hNSipNeLssUoHWz1wbMnCqLERXaIHngMKEr3xruZ0D/MKkD1atw+3ijFWC1ErBpZbwfocJhCwAYZhA6KBButdLulzaZ58IJB dutta.dipankar08@gmail.com
git@dipankar-OptiPlex-390:~/.ssh
dipankar@dipankar-OptiPlex-390:/opt$ sudo chmod -r  777 git
chmod: cannot access `777': No such file or directory
dipankar@dipankar-OptiPlex-390:/opt$ sudo chmod 777 git
dipankar@dipankar-OptiPlex-390:/opt$ sudo chown git:git  git
dipankar@dipankar-OptiPlex-390:/opt$ ll
total 12
drwxr-xr-x  3 root root 4096 Sep 13 12:23 ./
drwxr-xr-x 28 root root 4096 Sep 13 12:33 ../
drwxrwxrwx  2 git  git  4096 Sep 13 12:52 git/
dipankar@dipankar-OptiPlex-390:/opt$ su git
root@dipankar-OptiPlex-390:/home/git/.ssh# mkdir /opt/git
root@dipankar-OptiPlex-390:/home/git/.ssh# cd /opt/git/
root@dipankar-OptiPlex-390:/opt/git# mkdir project.git
root@dipankar-OptiPlex-390:/opt/git# cd project.git/
root@dipankar-OptiPlex-390:/opt/git/project.git# git --bare init
Initialized empty Git repository in /opt/git/project.git/

IN REMOTE MACHINE DO THE FOLLOWING AND ADD YOUR EXISTING CODE (ONE TIME)

root@dipankar-OptiPlex-390:/opt/git/project.git# mkdir /dipankar
root@dipankar-OptiPlex-390:/opt/git/project.git# cd /dipankar/
root@dipankar-OptiPlex-390:/dipankar# ls
root@dipankar-OptiPlex-390:/dipankar# git clone git@10.12.4.125:/opt/git/project.git
Cloning into 'project'...
The authenticity of host '10.12.4.125 (10.12.4.125)' can't be established.
ECDSA key fingerprint is 93:ea:51:ca:6c:2e:0f:0b:55:63:a1:da:4f:c3:c6:e1.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.12.4.125' (ECDSA) to the list of known hosts.
git@10.12.4.125's password: 
warning: You appear to have cloned an empty repository.
root@dipankar-OptiPlex-390:/dipankar# 
root@dipankar-OptiPlex-390:/dipankar# ls 
project

root@dipankar-OptiPlex-390:/dipankar# cd project/

root@dipankar-OptiPlex-390:/dipankar/project# vim hello.txt
root@dipankar-OptiPlex-390:/dipankar/project# git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
# hello.txt
nothing added to commit but untracked files present (use "git add" to track)
root@dipankar-OptiPlex-390:/dipankar/project# git add hello.txt 
root@dipankar-OptiPlex-390:/dipankar/project# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
# new file:   hello.txt
#
root@dipankar-OptiPlex-390:/dipankar/project# git diff

root@dipankar-OptiPlex-390:/dipankar/project# git commit -m " First Commit " 
[master (root-commit) d8bc11a]  First Commit
 1 file changed, 1 insertion(+)
 create mode 100644 hello.txt
[root@ravi project]# git remote rm origin
[root@ravi project]# git remote add origin git@10.12.4.125:/opt/git/project.git
[root@ravi project]# git push origin master
git@10.12.4.125's password: 
Counting objects: 3, done.
Writing objects: 100% (3/3), 196 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@10.12.4.125:/opt/git/project.git
 * [new branch]      master -> master
[root@ravi project]# git status
# On branch master
nothing to commit (working directory clean)
[root@ravi project]#

No comments:

Post a Comment