Upgrade to Pro — share decks privately, control downloads, hide ads and more …

İnsanlar İçin GIT

İnsanlar İçin GIT

Özgür Yazılım Günleri 2013'te yaptığım "İnsanlar İçin GIT" sunumu.

Uğur Özyılmazel

April 05, 2013
Tweet

More Decks by Uğur Özyılmazel

Other Decks in Programming

Transcript

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

    View Slide

  2. `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

    View Slide

  3. 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

    View Slide

  4. 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

    View Slide

  5. 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

    View Slide

  6. 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

    View Slide

  7. 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

    View Slide

  8. KURULUM
    Windows
    http://git-scm.com/download/win
    Linux
    `git-core` paketi
    Mac
    (Ön tanımlı)
    * İkonlar http://git-scm.com sitesine aittir.
    5 Nisan 13 Cuma

    View Slide

  9. İLK DEPO
    $ mkdir merhaba
    $ cd merhaba/
    $ git init
    Initialized empty Git repository in merhaba/.git/
    $ git help init
    5 Nisan 13 Cuma

    View Slide

  10. 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

    View Slide

  11. 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

    View Slide

  12. DOSYA OLUŞTURALIM
    $ echo "Proje ile ilgili bilgiler..." > README.md
    $ git status
    # On branch master
    #
    # Initial commit
    #
    # Untracked files:
    # (use "git add ..." to include in what will be committed)
    #
    #! README.md
    nothing added to commit but untracked files present (use "git add" to track)
    $ git help status
    5 Nisan 13 Cuma

    View Slide

  13. `git add`
    $ git add README.md
    $ git status
    # On branch master
    #
    # Initial commit
    #
    # Changes to be committed:
    # (use "git rm --cached ..." to unstage)
    #
    #! new file: README.md
    #
    $ git help add
    5 Nisan 13 Cuma

    View Slide

  14. `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

    View Slide

  15. `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

    View Slide

  16. 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

    View Slide

  17. `git log`
    $ git log
    commit 58d35a7b277811bd07677c406a0615cfb3fc7806
    Author: Uğur Özyılmazel
    Date: Wed Apr 3 06:48:03 2013 -0700
    Initial commit
    $ git help log
    5 Nisan 13 Cuma

    View Slide

  18. 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 ..." to include in what will be committed)
    #
    #! dosya1.txt
    #! dosya2.txt
    nothing added to commit but untracked files present (use "git add" to track)
    5 Nisan 13 Cuma

    View Slide

  19. YENİ DOSYALAR EKLEMEK
    # On branch master
    # Changes to be committed:
    # (use "git reset HEAD ..." 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

    View Slide

  20. YENİ DOSYALAR EKLEMEK
    commit bc0a6a64cf1b996ef3d133a199bc88e821a38456
    Author: Uğur Özyılmazel
    Date: Wed Apr 3 18:36:13 2013 +0300
    dosya1 ve dosya2 eklendi
    commit 58d35a7b277811bd07677c406a0615cfb3fc7806
    Author: Uğur Özyılmazel
    Date: Wed Apr 3 06:48:03 2013 -0700
    Initial commit
    $ git log
    5 Nisan 13 Cuma

    View Slide

  21. DEĞİŞİKLİK YAPMAK
    $ echo "dosya1'e ek" >> dosya1.txt
    $ cat dosya1.txt
    dosya1
    dosya1'e ek
    # dosya1.txt
    $ git status
    5 Nisan 13 Cuma

    View Slide

  22. DEĞİŞİKLİK YAPMAK
    $ git diff
    $ git help diff
    5 Nisan 13 Cuma

    View Slide

  23. 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

    View Slide

  24. DURUM KONTROLÜ
    $ git log --oneline
    c66dd49 dosya1'e ek satır
    bc0a6a6 dosya1 ve dosya2 eklendi
    58d35a7 Initial commit
    5 Nisan 13 Cuma

    View Slide

  25. 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

    View Slide

  26. 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

    View Slide

  27. DEĞİŞİKLİĞİ GERİ ALMAK
    EKLENMİŞ 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

    View Slide

  28. 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

    View Slide

  29. 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

    View Slide

  30. .gitignore
    $ touch .gitignore
    $ echo "*.jpg" >> .gitignore
    $ git status
    # On branch master
    # Untracked files:
    # (use "git add ..." to include in what will be committed)
    #
    ## .gitignore
    nothing 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

    View Slide

  31. .gitignore
    $ cp ~/Desktop/Linus_Torvalds.jpg .
    $ git status
    $ ls -al
    nothing to commit, working directory clean
    5 Nisan 13 Cuma

    View Slide

  32. 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

    View Slide

  33. BRANCH (DALLANMAK)
    $ git branch deneme
    $ git checkout deneme
    # Switched to branch 'deneme'
    $ git branch
    5 Nisan 13 Cuma

    View Slide

  34. dosya3.txt
    BRANCH (DALLANMAK)
    master deneme
    file_test.txt
    $ git help branch
    5 Nisan 13 Cuma

    View Slide

  35. BRANCH (DALLANMAK)
    $ git log --graph --decorate --oneline --all
    4a24e17
    5 Nisan 13 Cuma

    View Slide

  36. 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

    View Slide

  37. 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

    View Slide

  38. MERGE (BİRLEŞTİRMEK)
    deneme
    branch’inden
    geldi
    $ git help merge
    5 Nisan 13 Cuma

    View Slide

  39. 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

    View Slide

  40. CONFLICT (ÇAKIŞMA)
    $ git merge deneme # ve çakışma yaşanır!
    Auto-merging file_test.txt
    CONFLICT (content): Merge conflict in file_test.txt
    Automatic merge failed; fix conflicts and
    then commit the result.
    5 Nisan 13 Cuma

    View Slide

  41. CONFLICT (ÇAKIŞMA)
    $ git add file_test.txt
    $ git commit -m "çakışma düzeltildi"
    5 Nisan 13 Cuma

    View Slide

  42. 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

    View Slide

  43. 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

    View Slide

  44. 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

    View Slide

  45. 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

    View Slide

  46. 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

    View Slide

  47. `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

    View Slide

  48. `git-blame`
    SHA AUTHOR ve TARİH MESAJ
    $ git help blame
    5 Nisan 13 Cuma

    View Slide

  49. `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

    View Slide

  50. `git-diff`
    $ git diff HEAD^ HEAD file_test.txt
    5 Nisan 13 Cuma

    View Slide

  51. `git-diff`
    $ echo "3.satır" >> file_test.txt
    $ git diff file_test.txt
    5 Nisan 13 Cuma

    View Slide

  52. UZAK DEPO (REMOTE)
    Kişisel Sunucu
    Git Repo Sağlayıcılar
    5 Nisan 13 Cuma

    View Slide

  53. 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

    View Slide

  54. 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

    View Slide

  55. UZAK DEPO (REMOTE)
    $ git clone REPO_ADRESİ
    ssh://
    git://
    http(s)://
    ftp(s)://
    rsync://
    file://
    $ git help clone
    5 Nisan 13 Cuma

    View Slide

  56. UZAK DEPO (REMOTE)
    Git Repo Sağlayıcılar
    5 Nisan 13 Cuma

    View Slide

  57. Bitbucket
    5 Nisan 13 Cuma

    View Slide

  58. Bitbucket
    5 Nisan 13 Cuma

    View Slide

  59. 5 Nisan 13 Cuma

    View Slide

  60. 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

    View Slide

  61. 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

    View Slide

  62. github
    5 Nisan 13 Cuma

    View Slide

  63. github
    5 Nisan 13 Cuma

    View Slide

  64. 5 Nisan 13 Cuma

    View Slide

  65. 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

    View Slide

  66. 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

    View Slide

  67. 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

    View Slide

  68. UZAK DEPO (REMOTE)
    $ git help fetch
    5 Nisan 13 Cuma

    View Slide

  69. KONFİGÜRASYON
    $ git help config
    Kısa yol tanımlamaları ve SHELL
    komutları çalıştırılabilir.
    .gitconfig
    5 Nisan 13 Cuma

    View Slide

  70. ! işareti
    KONFİGÜRASYON
    $ git help config
    .gitconfig
    5 Nisan 13 Cuma

    View Slide

  71. 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

    View Slide

  72. 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

    View Slide

  73. 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

    View Slide

  74. 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

    View Slide

  75. DİĞER YARDIMCI ARAÇLAR
    Komut satırı dışında grafik arayüzle
    kullanılabilecek GIT araçları
    5 Nisan 13 Cuma

    View Slide

  76. DİĞER YARDIMCI ARAÇLAR
    Komut satırı dışında grafik arayüzle
    kullanılabilecek GIT araçları
    5 Nisan 13 Cuma

    View Slide

  77. 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

    View Slide

  78. DİĞER YARDIMCI ARAÇLAR
    http://jonas.nitro.dk/tig/
    tig
    5 Nisan 13 Cuma

    View Slide

  79. KİMLER KULLANIYOR?
    ■ Google
    ■ Facebook
    ■ Twitter
    ■ Microsoft
    ■ Perl
    ■ Android
    ■ Linux
    ■ QT
    ■ Gnome
    ■ PostgreSQL
    5 Nisan 13 Cuma

    View Slide

  80. 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

    View Slide

  81. Kaynak Kod
    https://github.com/vigo/oyg2013-git
    https://bitbucket.org/vigo/oyg2013-git
    5 Nisan 13 Cuma

    View Slide

  82. Teşekkürler
    @ugurozyilmazel
    @vigobronx
    http://ugur.ozyilmazel.com
    5 Nisan 13 Cuma

    View Slide