Friday, June 7, 2013

Make GIT on local

GIT basically used for listen our code changes in step by step. And we can revert back to any of these changes. This means  GIT does not totally backup our code for every changes, it just saving changes not all codes. From my point of view, this is the most short description for GIT.

For more clear details about GIT visit : http://git-scm.com/documentation

Now come to the point, We need to make GIT on local. GIT has one common stored are area where all our git data are saved. You may call this as GIT BARE REPOSITORY. And has one are more stored area which is used by programmer where they writing or changing coding. You may call this as GIT WORKING REPOSITORY.



Now you can understand our job easily, that is we need to make one GIT bare repository and more than one GIT working repository, and make a connection between them. That is changes on working repository need to saved or tracked in bare repository.

Reference: http://try.github.io/levels/1/challenges/1
(Most of the matter I noted follow are, learned from above link.)

Step 1: Make one directory for our whole work(called "git").

$ sudo mkdir git
$ sudo chmod 777 git (Changing file permissions. It may unnecessary)

Step 2: Make 'server' and 'client1' directory inside the folder "git".(Note: For only easy understanding I mentioned bare repository us 'server' and working repository us 'client1'. But there is no server and client in GIT.

$ cd git
$ sudo mkdir server
$ sudo chmod 777 server
$ sudo mkdir client1
$ sudo chmod 777 client1

Step 3: Setup 'server' folder as bare repository.

$ cd server
$ git init --bare

Output:
Initialized empty Git repository in /var/www/git/server/bare/.git/

Step 3: Setup 'client1' as working repository.

$ cd ..
$ cd client1
$ git init

Output:
Initialized empty Git repository in /var/www/git/client1/.git/

Step 4: Check status (Feel free to check status on any time, It not affect code.)

$ git status

Output:
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)

Step 5: Make one index.html file in 'client1'.  Content of index file is follows

<html>
<head>
<title>Git Test</title>
</head>
</html>

Step 6: Again check status

$ git status

Output:
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
# index.html
nothing added to commit but untracked files present (use "git add" to track)

Step 7: Now add this untracked file to stage. (Can check for "git status" after add to know file moved from untracked to stage)

$ git add index.html

Step 8: Now commit this add

$ git commit -m "first commit"

Output:
[master (root-commit) 3bdae52] first commit
 Committer: Ramasamy <ramasamy@dcmanilaptop-HP-430-Notebook-PC.(none)>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 9 insertions(+)
 create mode 100644 index.html

Step 9: This is important step so do carefully.

$ git remote add origin ../server/

//On above code 'origin' is a name of our repository. You can use anything. And last one is path to repository.

Step 10: Now push 'client1' datas to 'server'.

$ git push -u origin master

//Here origin is name of repository we made previously, and "master" is the name of  branch under repository. Default is pointing branch is "master". And "-u" used for remember current repository and branch name. So we need not give these when we push again.

Output:
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 314 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To ../server/
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

You can make more clients like we made 'client1' and make connection and interaction with them.

Graphical and live Demo avail here: http://try.github.io/levels/1/challenges/1

Thats all... We successfully made GIT on local.






No comments:

Post a Comment

Learn JavaScript - String and its methods - 16

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>String and it's methods - JS&l...