Tuesday 20 November 2012

GIT : Make Local Metadata Repository

When you want to develop your application efficiently with your team work. Git is the best way and it brings plenty of advantageous when build your application. Here, we would make local repository and use some command git that would be used frequently for your further or other project.

Repository contains metadata file that have complete history and full revision about everything that happen to your git working directory. Metadata can reduce the size in the repository. the metadata ussualy like the following:


Let's move out and configure in Terminal :

1. Make a repository
server@server-comp:~$ cd ~/repository
server@server-comp:~/repository$ mkdir contoh   // create dir as contoh
server@server-comp:~/repository$ cd contoh      // enter contoh directory
server@server-comp:~/repository/contoh$ ls -al  // view content in directory
total 8
drwxrwxr-x  2 server server 4096 Nov 20 11:24 .
drwxrwxrwx 36 server server 4096 Nov 20 11:24 ..
server@server-comp:~/repository/contoh$ git init   // initialize as git repo
Initialized empty Git repository in /home/server/repository/contoh/.git/
server@server-comp:~/repository/contoh$ ls -al
total 12
drwxrwxr-x  3 server server 4096 Nov 20 11:25 .
drwxrwxrwx 36 server server 4096 Nov 20 11:24 ..
drwxrwxr-x  7 server server 4096 Nov 20 11:25 .git
server@server-comp:~/repository/contoh$ vim contoh.txt  // create first file, fill with anything and save
server@server-comp:~/repository/contoh$ ls -al
total 16
drwxrwxr-x  3 server server 4096 Nov 20 11:25 .
drwxrwxrwx 36 server server 4096 Nov 20 11:24 ..
-rw-rw-r--  1 server server   20 Nov 20 11:25 contoh.txt
drwxrwxr-x  7 server server 4096 Nov 20 11:25 .git
server@server-comp:~/repository/contoh$ git add contoh.txt // add file(s) in directory
server@server-comp:~/repository/contoh$ git commit -m "bikin contoh.txt" -a // make a commit
[master (root-commit) 5852652] bikin contoh.txt
 1 file changed, 1 insertion(+)
 create mode 100644 contoh.txt
If you do it correctly, there must be a .git file. Then we move .git out into other folder that represent contoh repository , for example, contoh.git.

2. Move .git and change to other name
server@server-comp:~/repository/contoh$ mv .git/ ../contoh.git // move and rename .git in contoh dir
server@server-comp:~/repository/contoh$ ls -al
total 12
drwxrwxr-x  2 server server 4096 Nov 20 11:27 .
drwxrwxrwx 37 server server 4096 Nov 20 11:27 ..
-rw-rw-r--  1 server server   20 Nov 20 11:25 contoh.txt
server@server-comp:~/repository/contoh$ cd ..
server@server-comp:~/repository$ rm -rf contoh/    // remove contoh directory
server@server-comp:~/repository$ cd contoh.git/
server@server-comp:~/repository/contoh.git$ git init --bare  // reinitialized git repository
Reinitialized existing Git repository in /home/server/repository/contoh.git/

3. Clone to .git to www file project
server@server-comp:~/repository/contoh.git$ cd ~www-data/
server@server-comp:/var/www$ git clone ~/repository/contoh.git/  // clone repository in www-data
Cloning into 'contoh'...
done.

4. Edit file on our project directory
server@server-comp:/var/www$ cd contoh/
server@server-comp:/var/www/contoh$ ls -al
total 16
drwxr-xr-x  3 server server 4096 Nov 20 11:28 .
drwxrwxrwx 88 server server 4096 Nov 20 11:28 ..
-rw-rw-r--  1 server server   20 Nov 20 11:28 contoh.txt
drwxrwxr-x  8 server server 4096 Nov 20 11:28 .git
server@server-comp:/var/www/contoh$ vim contoh.txt    // edit contoh.txt that filled anything you want

5. Add and commit the change
server@server-comp:/var/www/contoh$ git status   // check status
# On branch master
# Changes not staged for commit:
#   (use "git add ..." to update what will be committed)
#   (use "git checkout -- ..." to discard changes in working directory)
#
# modified:   contoh.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
server@server-comp:/var/www/contoh$ git add .   // git add . means everything in the dir
server@server-comp:/var/www/contoh$ git commit -m "edit contoh.txt" -a  // second commit after editing
[master 4d1a083] edit contoh.txt
 1 file changed, 1 insertion(+), 1 deletion(-)

5. Push to repository
server@server-comp:/var/www/contoh$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
nothing to commit (working directory clean)
server@server-comp:/var/www/contoh$ git push    // push to the main repo
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 291 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To /home/server/repository/contoh.git/
   5852652..4d1a083  master -> master

Note :
  • git init = create local repository.
  • git init --bare = initialization Git working as a remote backup repository, you can clone that remote repository and push files back into it.
  • git add . = add all file (.) in directory.
  • git status = view all status (changes in our working directory ).
  • git commit -m " your description " -a = commit all local changes in tracked files.
  • git push = push to central Git repository.

Reference :

1. https://samsonasik.wordpress.com/2012/11/05/practical-git-1-manage-repository-that-metadata-only/
2. http://www.bitflop.com/document/111
3. http://en.wikipedia.org/wiki/Git_%28software%29
Copyright © 2012 Clighter | Powered by Blogger