Pengenalan Git

Fajran Iman Rusadi
https://github.com/fajran/slide-pengenalan-git

Creative Commons Attribution-ShareAlike 3.0 Unported  

 

Version Control System

Pengelola perubahan
Karedok * Ketimun * Tauge * Kol * Kacang panjang * Daun kemangi * Terong Karedok * Ketimun, direbus sebentar * Tauge * Kol, iris halus * Kacang panjang, rebus sebentar * Daun kemangi * Terong

Contoh: Subversion, Bazaar, Mercurial, Git

 

 

Resep dari http://id.wikibooks.org/wiki/Resep:Karedok

Alur Kerja
1. Buat repositori 2. Salin revisi 3. Ubah, tambah, hapus 4. Kirim perubahan ke repositori

2 1
   

3 4

Terpusat vs Terdistribusi
Repositori Utama Repositori

Repositori Pribadi

Direktori Kerja Direktori Kerja

 

 

Alur Kerja Tambahan
 

Salin repositori Kirim perubahan ke repositori lain

 

 

git init

Membuat repositori baru

$ mkdir resep $ cd resep $ git init $ ls -a
. ..

Initialized empty Git repository in /home/iang/resep/.git/ .git

 

 

git add

Mendaftarkan berkas untuk disimpan

$ vi karedok.txt $ git add karedok.txt

Konsep penting untuk diketahui: staging area Akan dibahas nanti!

 

 

git commit

Menyimpan perubahan ke repositori

$ git commit -m "resep karedok"

[master (root-commit) 066ee9e] resep karedok 1 files changed, 8 insertions(+), 0 deletions(-) create mode 100644 karedok.txt

Hanya akan menyimpan perubahan yang sudah dimasukkan ke dalam staging area

 

 

Staging Area

Berisi perubahan yang akan disimpan pada saat commit Berguna untuk commit secara selektif

Repositori Pribadi

Staging Area

Direktori Kerja

 

 

Git Philosophy
 

Commit early, commit often One commit represents one idea or one change. Your working directory, index, and local repo are your scratch pads.
Advanced Git Tutorial by Sarah Sharp http://thesharps.us/~sarah/advanced-git.pdf

 

 

git add
 

Menambahkan berkas baru Menyimpan perubahan ke staging area

$ vi karedok.txt $ git commit -m "tambah petunjuk"

# On branch master # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: karedok.txt # no changes added to commit (use "git add" and/or "git commit -a")

$ git add karedok.txt $ git commit -m "tambah petunjuk"

[master 84801e1] tambah petunjuk 1 files changed, 3 insertions(+), 3 deletions(-)

 

 

Ilustrasi Staging Area
kondisi sebelum git add

$ vi karedok.txt $ git status

Perubahan dibuat

# On branch master # Changed but not updated: # # modified: karedok.txt #

Perubahan terdeteksi namun belum masuk ke staging area

$ git add karedok.txt $ git status
# On branch master # Changes to be committed: # # modified: karedok.txt #

Memasukkan perubahan ke staging area

Perubahan tercatat di staging area

 

 

Kolaborasi
1. Menyalin repositori 2. Membuat perubahan lokal 3. Mengirim perubahan ke repositori lain

 

 

git clone

Menyalin repositori

$ git clone git://git.debian.org/debian-id/webwml-id.git
Initialized empty Git repository in /home/iang/webwml-id/.git/ remote: Counting objects: 82, done. remote: Compressing objects: 100% (74/74), done. remote: Total 82 (delta 17), reused 0 (delta 0) Receiving objects: 100% (82/82), 49.61 KiB, done. Resolving deltas: 100% (17/17), done.

$ ls

webwml-id

 

 

git log

Melihat riwayat perubahan

$ git log

commit 9d014350974f00670b1c694fb71d72037e677f9a Author: Izharul Haq <atoz@debian-id.org> Date: Fri Dec 3 06:55:58 2010 +0700 Request For Review commit 3fd26492e4feeb1ee835e8261b66aa5975d99074 Author: Izharul Haq <atoz@debian-id.org> Date: Thu Dec 2 19:07:36 2010 +0700 Re-adding file license.wml after dead revision 1.5 commit c3dbd03a7947cc0feefe658dbe57f757358eeba1 Author: Izharul Haq <atoz@debian-id.org> Date: Thu Dec 2 18:47:46 2010 +0700 Initial translations ...
   

git remote

Repositori lain yang dipakai

$ git remote
origin

$ git remote show origin

* remote origin Fetch URL: git://git.debian.org/debian-id/webwml-id.git Push URL: git://git.debian.org/debian-id/webwml-id.git HEAD branch: master Remote branch: master tracked Local branch configured for 'git pull': master merges with remote master Local ref configured for 'git push': master pushes to master (up to date)

 

 

git push

Mengirim perubahan ke repositori lain

$ git push origin master

Counting objects: 4, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 288 bytes, done. Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. To /home/iang/webwml-id.git 9d01435..b6cbae8 master -> master

 

 

Sign up to vote on this title
UsefulNot useful