Practical GIT (1) : Manage Repository That Metadata only
In software development, Git is a distributed revision control and source code management (SCM) system with an emphasis on speed. Git was initially designed and developed by Linus Torvalds for Linux kernel development; it has since been adopted by many other projects. Every Git working directory is a full-fledged repository with complete history and full revision tracking capabilities, not dependent on network access or a central server.
In this post, i want to show you how to create a repository as metadata only, it can reduce the size in the repository. the metadata(only) we will create will be like the following :
Let’s configure in terminal :
Abduls-MacBook-Pro:repositories abdulmalikikhsan$ mkdir testrepo // create a dir named testrepo Abduls-MacBook-Pro:repositories abdulmalikikhsan$ cd testrepo // enter testrepo folder Abduls-MacBook-Pro:testrepo abdulmalikikhsan$ git init . //initialize as git repo Initialized empty Git repository in /Users/abdulmalikikhsan/Documents/repositories/testrepo/.git/ Abduls-MacBook-Pro:testrepo abdulmalikikhsan$ vim test.txt //create first file, edit, and save Abduls-MacBook-Pro:testrepo abdulmalikikhsan$ ls -al //show the file ( we have a file ! ) total 8 drwxr-xr-x 4 abdulmalikikhsan staff 136 Nov 5 12:49 . drwxr-xr-x 5 abdulmalikikhsan staff 170 Nov 5 12:48 .. drwxr-xr-x 10 abdulmalikikhsan staff 340 Nov 5 12:48 .git -rw-r--r-- 1 abdulmalikikhsan staff 11 Nov 5 12:49 test.txt Abduls-MacBook-Pro:testrepo abdulmalikikhsan$ git add . //add the file(s) in directory Abduls-MacBook-Pro:testrepo abdulmalikikhsan$ git commit -m "first commit" test.txt //first commit [master (root-commit) ae96d7f] first commit 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 test.txt
While commit success, we move the folder “.git” (only) into other folder that represent testrepo, for example, testrepo.git, it only contains metadata.
Abduls-MacBook-Pro:testrepo abdulmalikikhsan$ mv .git/ ../testrepo.git Abduls-MacBook-Pro:testrepo abdulmalikikhsan$ cd .. Abduls-MacBook-Pro:repositories abdulmalikikhsan$ cd testrepo.git/ Abduls-MacBook-Pro:testrepo.git abdulmalikikhsan$ git init --bare Reinitialized existing Git repository in /Users/abdulmalikikhsan/Documents/repositories/testrepo.git/ Abduls-MacBook-Pro:testrepo.git abdulmalikikhsan$ cd .. Abduls-MacBook-Pro:repositories abdulmalikikhsan$ rm -rf testrepo/ //remove "old" directory
Next, check if repository is working properly :
Abduls-MacBook-Pro:www abdulmalikikhsan$ git clone ~/Documents/repositories/testrepo.git/ testclone Cloning into 'testclone'... done. Abduls-MacBook-Pro:www abdulmalikikhsan$ cd testclone/ Abduls-MacBook-Pro:testclone abdulmalikikhsan$ ls -al total 8 drwxr-xr-x 4 abdulmalikikhsan staff 136 Nov 5 12:52 . drwxr-xr-x 101 abdulmalikikhsan staff 3434 Nov 5 12:52 .. drwxr-xr-x 13 abdulmalikikhsan staff 442 Nov 5 12:52 .git -rw-r--r-- 1 abdulmalikikhsan staff 11 Nov 5 12:52 test.txt Abduls-MacBook-Pro:testclone abdulmalikikhsan$ vim test.txt //edit file Abduls-MacBook-Pro:testclone abdulmalikikhsan$ git status # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: test.txt # no changes added to commit (use "git add" and/or "git commit -a") Abduls-MacBook-Pro:testclone abdulmalikikhsan$ git commit -m "tet" -a [master 5c514e4] tet 1 files changed, 1 insertions(+), 1 deletions(-) Abduls-MacBook-Pro:testclone abdulmalikikhsan$ git push Counting objects: 5, done. Writing objects: 100% (3/3), 253 bytes, done. Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. To /Users/abdulmalikikhsan/Documents/repositories/testrepo.git/ ae96d7f..5c514e4 master -> master
Ok, success!
Reference :
http://en.wikipedia.org/wiki/Git_%28software%29
5 Responses
Subscribe to comments with RSS.
seger gitu mas 😀 tp saya gangerti :p
hahahaha
hahahaah 😀
Hi….is there any way of contacting you..Needed some information..
You can contact me via email : samsonasik@gmail.com
[…] got one feature that I really like, named hooks. With hooks, we can configure what GIT do after metadata pushed to the remote server. It can ease our development because we don’t need to upload file […]