İnsanlar için GIT

82
İNSANLAR İÇİN “GIT” Uğur Özyılmazel - http://ugur.ozyilmazel.com @ugurozyilmazel 5 Nisan 13 Cuma

description

Sürüm kontrol sistemi GIT ile tanışmak. Neden sürüm kontrol sistemi gereklidir? Dağıtık olarak çalışmak, branch / merge gibi temel GIT özellikleri.

Transcript of İnsanlar için GIT

Page 1: İnsanlar için GIT

İNSANLAR İÇİN “GIT”Uğur Özyılmazel - http://ugur.ozyilmazel.com

@ugurozyilmazel

5 Nisan 13 Cuma

Page 2: İnsanlar için GIT

`git`NEDİR?

Dağıtık çalışan sürüm kontrol (DVCS*) ve kaynak kod yönetim (SCM*) aracıdır.

* DVCS : Distributed Version Control System SCM : Source Code Management

5 Nisan 13 Cuma

Page 3: İnsanlar için GIT

SÜRÜM KONTROL ?

■ Kaynak kod yönetimi

■ Sürüm (Versiyon) Takibi

■ Birden fazla kişiyle çalışma ve paylaşma

■ Repository (Depo) hizmeti

■ Deployment (Sunucuya uygulamanın kurulumu)

5 Nisan 13 Cuma

Page 4: İnsanlar için GIT

TARİHÇE

★ Linus Torvalds

★ Aralık 2005, V 1.0

★ Nisan 2013, V 1.8.2

http://en.wikipedia.org/wiki/Linus_Torvalds

5 Nisan 13 Cuma

Page 5: İnsanlar için GIT

DİĞER UYGULAMALAR

CVS

SVN

MERCURIAL

* Lisans sorunları yüzünden Linus Torvalds GIT’i yazdı!

BITKEEPER *

PERFORCE

BAZAAR

# http://en.wikipedia.org/wiki/Comparison_of_revision_control_software

5 Nisan 13 Cuma

Page 6: İnsanlar için GIT

GIT`İ ÖNE ÇIKARANLAR

Dallanma ve Birleştirme(Branch, Merge)

Dağıtık Çalışma(Distributed)

Güvenlik(Checksum ve SHA)

Hız ve Boyut(Clone ve Depolama)

Ön İzleme(Staging)

Açık Kaynak(GPL V2)

5 Nisan 13 Cuma

Page 7: İnsanlar için GIT

TEKNİK FARKLAR

■ Dosya içeriği BLOB* şeklinde saklanır. Blob’ların kendine ait modu, tipi, adı ve SHA**’sı bulunur

■ Dizinler’e Tree (Ağaç) adı verilir.

■ Her Tree, alt Tree’lere ve Blob’lara sahiptir.

■ Log, COMMIT OBJECT adı verilen bir sistemde saklanır. (Author, Commiter ve ilişkili diğer bilgiler)

* Binary Large Objects** Secure Hash Algorithm

5 Nisan 13 Cuma

Page 8: İnsanlar için GIT

KURULUM

Windowshttp://git-scm.com/download/win

Linux`git-core` paketi

Mac(Ön tanımlı)

* İkonlar http://git-scm.com sitesine aittir.

5 Nisan 13 Cuma

Page 9: İnsanlar için GIT

İLK DEPO

$ mkdir merhaba$ cd merhaba/$ git init

Initialized empty Git repository in merhaba/.git/

$ git help init

5 Nisan 13 Cuma

Page 10: İnsanlar için GIT

BOŞ DEPO

■ İlk COMMIT yapılana kadar ortada BRANCH yoktur!

■ İlk commit yapıldıktan sonra varsayılan (default) branch oluşur ve adı MASTER olur.

5 Nisan 13 Cuma

Page 11: İnsanlar için GIT

KONFİGÜRASYON

$ git config --global user.name "Adınız Soyadınız"$ git config --global user.email "[email protected]"

GIT konfigürasyon dosyası~/.gitconfig

$ git help config

5 Nisan 13 Cuma

Page 12: İnsanlar için GIT

DOSYA OLUŞTURALIM

$ echo "Proje ile ilgili bilgiler..." > README.md$ git status

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

$ git help status

5 Nisan 13 Cuma

Page 13: İnsanlar için GIT

`git add`

$ git add README.md$ git status

# On branch master## Initial commit## Changes to be committed:# (use "git rm --cached <file>..." to unstage)##! new file: README.md#

$ git help add

5 Nisan 13 Cuma

Page 14: İnsanlar için GIT

`git commit`

$ git commit -m “Initial commit”$ git status

[master (root-commit) 58d35a7] init 1 file changed, 1 insertion(+) create mode 100644 README.md

SHA (Kısa)

58d35a7b277811bd07677c406a0615cfb3fc7806

SHA (UZUN - 40 byte / karakter)

$ git help commit

5 Nisan 13 Cuma

Page 15: İnsanlar için GIT

`git commit`

Bir tür zamanı dondurmak, o an’ı kaydetmek / yakalamak, SNAPSHOT çıkartmaktır.

SNAPSHOT: An, enstantane fotoğraf anlamındadır...

5 Nisan 13 Cuma

Page 16: İnsanlar için GIT

MESAJ EDİTÖRÜ

İlgili çevre değişkenini (Environment Variable) kullanarak istediğiniz metin düzenleyicisini kullanabilirsiniz.

export GIT_EDITOR="emacs"export VISUAL="vim"export EDITOR="mate"

~/.bashrc # Örnek olarak

5 Nisan 13 Cuma

Page 17: İnsanlar için GIT

`git log`

$ git log

commit 58d35a7b277811bd07677c406a0615cfb3fc7806Author: Uğur Özyılmazel <[email protected]>Date: Wed Apr 3 06:48:03 2013 -0700

Initial commit

$ git help log

5 Nisan 13 Cuma

Page 18: İnsanlar için GIT

YENİ DOSYALAR EKLEMEK

$ echo "dosya1" > dosya1.txt$ echo "dosya2" > dosya2.txt$ ls

README.md dosya1.txt dosya2.txt

$ git status

# On branch master# Untracked files:# (use "git add <file>..." to include in what will be committed)##! dosya1.txt#! dosya2.txtnothing added to commit but untracked files present (use "git add" to track)

5 Nisan 13 Cuma

Page 19: İnsanlar için GIT

YENİ DOSYALAR EKLEMEK

# On branch master# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)##! new file: dosya1.txt#! new file: dosya2.txt#

$ git commit -m "dosya1 ve dosya2 eklendi"

$ git add .$ git status NOKTA İŞARETİ

5 Nisan 13 Cuma

Page 20: İnsanlar için GIT

YENİ DOSYALAR EKLEMEK

commit bc0a6a64cf1b996ef3d133a199bc88e821a38456Author: Uğur Özyılmazel <[email protected]>Date: Wed Apr 3 18:36:13 2013 +0300

dosya1 ve dosya2 eklendi

commit 58d35a7b277811bd07677c406a0615cfb3fc7806Author: Uğur Özyılmazel <[email protected]>Date: Wed Apr 3 06:48:03 2013 -0700

Initial commit

$ git log

5 Nisan 13 Cuma

Page 21: İnsanlar için GIT

DEĞİŞİKLİK YAPMAK

$ echo "dosya1'e ek" >> dosya1.txt$ cat dosya1.txt

dosya1dosya1'e ek

# dosya1.txt

$ git status

5 Nisan 13 Cuma

Page 22: İnsanlar için GIT

DEĞİŞİKLİK YAPMAK

$ git diff

$ git help diff

5 Nisan 13 Cuma

Page 23: İnsanlar için GIT

DEĞİŞİKLİK YAPMAK

$ git add dosya1.txt # onayla$ git commit -m “dosya1’e ek satır”

$ git checkout -- dosya1.txt # iptal

$ git help checkout

5 Nisan 13 Cuma

Page 24: İnsanlar için GIT

DURUM KONTROLÜ

$ git log --oneline

c66dd49 dosya1'e ek satırbc0a6a6 dosya1 ve dosya2 eklendi58d35a7 Initial commit

5 Nisan 13 Cuma

Page 25: İnsanlar için GIT

AĞAÇ YAPISI

Github’daki depo’nun durumu. “origin” remote adı. Son snapshot’daki HEAD ve branch.

Yerel makinedeki en son snapshot’a göre HEAD ve branch.

5 Nisan 13 Cuma

Page 26: İnsanlar için GIT

AĞAÇ YAPISI$ git push -u origin master # uzaktaki depoya

Hem uzaktaki, hem de yereldeki SNAPSHOT eşitlendi.$ git help push

5 Nisan 13 Cuma

Page 27: İnsanlar için GIT

DEĞİŞİKLİĞİ GERİ ALMAKEKLENMİŞ dosyayı geri almak (staged)

DÜZENLENMİŞ dosyayı geri almak (modified)

REVİZYON seviyesinde projeyi geri almak

$ git reset HEAD DOSYA_ADI

$ git reset --soft SHA

$ git checkout -- DOSYA_ADI

$ git help reset

5 Nisan 13 Cuma

Page 28: İnsanlar için GIT

DOSYA SİLMEK / TAŞIMAK

$ git rm DOSYA_ADI$ git rm file1.txt

rm (remove)

$ git mv DOSYA_ADI TAŞINACAK/DOSYA_ADI$ git mv file1.txt yedek/file1.txt

mv (move)

$ git help mv

$ git help rm

5 Nisan 13 Cuma

Page 29: İnsanlar için GIT

VERSİYONLAMA YAPMA!

Bazı dosyaları ya da dizinleri sürüm kontrolü dışında tutmak gerekebilir. Bunun için: .gitignore dosyasını kullanıyoruz.

5 Nisan 13 Cuma

Page 30: İnsanlar için GIT

.gitignore$ touch .gitignore$ echo "*.jpg" >> .gitignore$ git status

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

$ git commit -m "jpg dosyaları sürüm kontrolünden çıkartıldı"

5 Nisan 13 Cuma

Page 31: İnsanlar için GIT

.gitignore

$ cp ~/Desktop/Linus_Torvalds.jpg .$ git status

$ ls -al

nothing to commit, working directory clean

5 Nisan 13 Cuma

Page 32: İnsanlar için GIT

BRANCH (DALLANMAK)

$ git branch # yerel branch’leri listeler$ git branch -r # uzak branch’leri listeler

Ağaç yapısını, kodu ve depoyu bozmadan kopyalar çıkartmak ve daha sonra bu kopyaları ana yapıya entegre etmek

$ git help branch

5 Nisan 13 Cuma

Page 33: İnsanlar için GIT

BRANCH (DALLANMAK)

$ git branch deneme$ git checkout deneme# Switched to branch 'deneme'$ git branch

5 Nisan 13 Cuma

Page 34: İnsanlar için GIT

dosya3.txt

BRANCH (DALLANMAK)

master deneme

file_test.txt

$ git help branch

5 Nisan 13 Cuma

Page 35: İnsanlar için GIT

BRANCH (DALLANMAK)

$ git log --graph --decorate --oneline --all

4a24e175 Nisan 13 Cuma

Page 36: İnsanlar için GIT

BRANCH (DALLANMAK)

$ git branch BRANCH_ADI REVİZYON$ git branch deneme2 4a24e17

İstediğiniz herhangi bir revizyondan da branch oluşturabilirsiniz.

$ git help branch

5 Nisan 13 Cuma

Page 37: İnsanlar için GIT

MERGE (BİRLEŞTİRMEK)

deneme branch’indeki tüm değişiklikleri master’a taşıyoruz.

$ git merge BRANCH_ADI$ git merge deneme

5 Nisan 13 Cuma

Page 38: İnsanlar için GIT

MERGE (BİRLEŞTİRMEK)

deneme branch’inden geldi

$ git help merge

5 Nisan 13 Cuma

Page 39: İnsanlar için GIT

CONFLICT (ÇAKIŞMA)Farklı branch’lerde, aynı isimli dosyalarda değişiklik yapalım.

$ git checkout deneme$ echo "2.satır" >> file_test.txt $ git add file_test.txt$ git commit -m "file_test.txt'ye 2.satır eklendi"

deneme

master$ git checkout master$ echo "master'daki file_test.txt'ye 2.satır" >> file_test.txt$ git add file_test.txt$ git ci -m "master'daki file_test.txt'ye 2.satır eklendi"

5 Nisan 13 Cuma

Page 40: İnsanlar için GIT

CONFLICT (ÇAKIŞMA)$ git merge deneme # ve çakışma yaşanır!

Auto-merging file_test.txtCONFLICT (content): Merge conflict in file_test.txtAutomatic merge failed; fix conflicts andthen commit the result.

5 Nisan 13 Cuma

Page 41: İnsanlar için GIT

CONFLICT (ÇAKIŞMA)

$ git add file_test.txt$ git commit -m "çakışma düzeltildi"

5 Nisan 13 Cuma

Page 42: İnsanlar için GIT

BRANCH SİLMEK

$ git branch -d BRANCH_ADI # yerel$ git push origin :BRANCH_ADI # uzaktaki

İşi biten branch’i düzeni korumak adına silebilirsiniz.

5 Nisan 13 Cuma

Page 43: İnsanlar için GIT

TAG (ETİKET)

http://bit.ly/git-tag

Bulunduğunuz an’dan / branch’den versiyon oluşturmak ya da o an’ı etiketlemek için kullanılır.

$ git tag # yerel tag’leri listeler$ git ls-remote --tags # uzak branch’leri listeler

5 Nisan 13 Cuma

Page 44: İnsanlar için GIT

TAG (ETİKET)

$ git tag ETİKET_ADI$ git tag -a ETİKET_ADI -m “COMMIT Mesajı”

İstediğiniz herhangi bir revizyondan da TAG yapmanız mümkün.

Annotated TAG / Not düşülmüş Etiket

$ git help tag

5 Nisan 13 Cuma

Page 45: İnsanlar için GIT

TAG (ETİKET)Aynı branch gibi çalışır. checkout edilebilirler.

V1.0 İlk commit. İçinde hiçbir şey yok. *.jpg’de ignore edildiği için kontrol dışında!

5 Nisan 13 Cuma

Page 46: İnsanlar için GIT

TAG (ETİKET) SİLMEK

$ git tag -d ETİKET_ADI # yerel$ git push origin :ETİKET_ADI # uzaktaki

Aynı branch’lerdeki gibi, tag’leri de silebilirsiniz.

$ git help tag

5 Nisan 13 Cuma

Page 47: İnsanlar için GIT

`git-blame`

Hangi kullanıcı, hangi dosyada ne işlem yapmış, ne değiştirmiş, kim kod’u bozmuş!

$ git blame DOSYA_ADI$ git blame dosya1.txt

$ git help blame

5 Nisan 13 Cuma

Page 48: İnsanlar için GIT

`git-blame`

SHA AUTHOR ve TARİH MESAJ

$ git help blame

5 Nisan 13 Cuma

Page 49: İnsanlar için GIT

`git-diff`

$ git diff HEAD^ HEAD file_test.txt

`diff`ile versiyonlar arasındaki farkları görüntülemeye yarar.

$ git help diff

5 Nisan 13 Cuma

Page 50: İnsanlar için GIT

`git-diff`

$ git diff HEAD^ HEAD file_test.txt

5 Nisan 13 Cuma

Page 51: İnsanlar için GIT

`git-diff`

$ echo "3.satır" >> file_test.txt $ git diff file_test.txt

5 Nisan 13 Cuma

Page 52: İnsanlar için GIT

UZAK DEPO (REMOTE)

Kişisel Sunucu

Git Repo Sağlayıcılar

5 Nisan 13 Cuma

Page 53: İnsanlar için GIT

UZAK DEPO (REMOTE)

Kişisel Sunucu

$ mkdir /git/depo/projem.git$ cd /git/depo/projem.git$ git init --bare$ git config receive.denyCurrentBranch false$ git repo-config core.sharedRepository true

$ git clone git+ssh://kullanici@sunucu/git/depo/projem.git$ git clone git+ssh://sunucu/git/depo/projem.git

5 Nisan 13 Cuma

Page 54: İnsanlar için GIT

UZAK DEPO (REMOTE)

Kişisel Sunucu

■ http://gitorious.org/download

■ http://gitlab.org

■ https://github.com/sitaramc/gitolite

■ http://gitblit.com

5 Nisan 13 Cuma

Page 55: İnsanlar için GIT

UZAK DEPO (REMOTE)

$ git clone REPO_ADRESİ

ssh://

git://

http(s)://

ftp(s)://

rsync://

file://

$ git help clone

5 Nisan 13 Cuma

Page 56: İnsanlar için GIT

UZAK DEPO (REMOTE)

Git Repo Sağlayıcılar

5 Nisan 13 Cuma

Page 57: İnsanlar için GIT

Bitbucket

5 Nisan 13 Cuma

Page 58: İnsanlar için GIT

Bitbucket

5 Nisan 13 Cuma

Page 59: İnsanlar için GIT

5 Nisan 13 Cuma

Page 60: İnsanlar için GIT

UZAK DEPO (REMOTE)

Yerel git deposunu Bitbucket’a taşımak için önce Bitbucket’da depo oluşturun daha sonra yereldeki depoya REMOTE ekleyin.

$ git remote add REMOTE_ADI URL

$ git help remote

5 Nisan 13 Cuma

Page 61: İnsanlar için GIT

Track Remote Branch

$ git push -u origin master$ git push

$ git push bitbucket$ git push bitbucket master

UZAK DEPO (REMOTE)$ git remote add origin ssh://[email protected]/vigo/oyg2013-git.git$ git remote add bitbucket ssh://[email protected]/vigo/oyg2013-git.git

5 Nisan 13 Cuma

Page 62: İnsanlar için GIT

github

5 Nisan 13 Cuma

Page 63: İnsanlar için GIT

github

5 Nisan 13 Cuma

Page 64: İnsanlar için GIT

5 Nisan 13 Cuma

Page 65: İnsanlar için GIT

UZAK DEPO (REMOTE)

$ git pull$ git pull REMOTE_ADI BRANCH_ADI$ git pull --all

$ git help pull

Uzaktaki değişiklikleri almak için

pull ve fetch

5 Nisan 13 Cuma

Page 66: İnsanlar için GIT

UZAK DEPO (REMOTE)

$ git fetch$ git fetch REMOTE_ADI BRANCH_ADI$ git fetch --all

$ git help fetch

Uzaktaki değişiklikleri almak için

pull ve fetch

5 Nisan 13 Cuma

Page 67: İnsanlar için GIT

UZAK DEPO (REMOTE)

pull ve fetch arasındaki fark;

pull : önce fetch sonra merge

fetch : sadece fetch

$ git help pull && git help fetch

5 Nisan 13 Cuma

Page 68: İnsanlar için GIT

UZAK DEPO (REMOTE)

$ git help fetch

5 Nisan 13 Cuma

Page 69: İnsanlar için GIT

KONFİGÜRASYON

$ git help config

Kısa yol tanımlamaları ve SHELL komutları çalıştırılabilir.

.gitconfig

5 Nisan 13 Cuma

Page 70: İnsanlar için GIT

! işareti

KONFİGÜRASYON

$ git help config

.gitconfig

5 Nisan 13 Cuma

Page 71: İnsanlar için GIT

GIT FLOW

http://nvie.com/posts/a-successful-git-branching-model/

Standart repo’daki master branch, git-flow’da develop branch’i olur.

5 Nisan 13 Cuma

Page 72: İnsanlar için GIT

GIT FLOW

https://github.com/nvie/gitflow

Tüm kullanıcılar git-flow kurmalı ve master / develop branch’leri olmalı

$ git flow init$ git flow feature start ozellik1$ git flow feature finish ozellik1$ git flow release start r1$ git flow release finish 'r1'

5 Nisan 13 Cuma

Page 73: İnsanlar için GIT

GIT FLOW

https://github.com/nvie/gitflow

$ git flow feature finish ozellik1

■ feature/ozellik1, develop’la merge

■ feature/ozellik1 siliniyor

■ develop branch’e geçiliyor (checkout)

5 Nisan 13 Cuma

Page 74: İnsanlar için GIT

GIT FLOW

https://github.com/nvie/gitflow

$ git flow release finish 'r1'

■ önce origin’den fetch

■ release/r1 master’la merge

■ ‘r1’ tag’lenir

■ develop’la merge

■ release/r1 silinir

5 Nisan 13 Cuma

Page 75: İnsanlar için GIT

DİĞER YARDIMCI ARAÇLARKomut satırı dışında grafik arayüzle kullanılabilecek GIT araçları

5 Nisan 13 Cuma

Page 76: İnsanlar için GIT

DİĞER YARDIMCI ARAÇLARKomut satırı dışında grafik arayüzle kullanılabilecek GIT araçları

5 Nisan 13 Cuma

Page 77: İnsanlar için GIT

DİĞER YARDIMCI ARAÇLAR

ÜCRETSİZ ÜCRETLİ

Github App

Sourcetree

GitX(L)

git-cola

Tower

Gitbox

SmartGit

git-cola

http://git-scm.com/downloads/guis

5 Nisan 13 Cuma

Page 78: İnsanlar için GIT

DİĞER YARDIMCI ARAÇLAR

http://jonas.nitro.dk/tig/

tig

5 Nisan 13 Cuma

Page 79: İnsanlar için GIT

KİMLER KULLANIYOR?

■ Google

■ Facebook

■ Twitter

■ Microsoft

■ Perl

■ Android

■ Linux

■ QT

■ Gnome

■ PostgreSQL

5 Nisan 13 Cuma

Page 80: İnsanlar için GIT

KAYNAKLAR

■ http://git.gelistiriciyiz.biz/ *

■ http://git-scm.com

■ http://try.github.com

■ http://gitimmersion.com

■ http://www.codeschool.com/courses/git-real

* Türkçe

5 Nisan 13 Cuma

Page 81: İnsanlar için GIT

Kaynak Kod

https://github.com/vigo/oyg2013-git

https://bitbucket.org/vigo/oyg2013-git

5 Nisan 13 Cuma

Page 82: İnsanlar için GIT

Teşekkürler

@ugurozyilmazel

@vigobronx

http://ugur.ozyilmazel.com

5 Nisan 13 Cuma