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

Git and Github for Beginners

Git and Github for Beginners

This is a textbook for beginner to learn Git and Github, design for G's Academy Tokyo, presented by yoheiMune (http://www.yoheim.net).

Yohei Munesada

June 06, 2017
Tweet

More Decks by Yohei Munesada

Other Decks in Technology

Transcript

  1. Agenda 1. Basic1  όʔδϣϯ؅ཧͱ͸  (JUͷجຊίϚϯυ  (JUIVCͱ͸ 

    4PVSDF5SFFΛ࢖͏  ԋश 2. Basic2  ίϯϑϦΫτͷղফ  ԋश 3. Advance  ϒϥϯνͱϓϧϦΫ  ԋश  5JQT  ࠓճઆ໌͠ͳ͔ͬͨ͜ͱ 4. Summary
  2. main.js main2.js main_20160428.js main_20160429.js main_20160429_2.js main_20160429_verB.js 426  427 

      428   429  429   429    Version Control - ϑΝΠϧ໊Λۦ࢖͢Δ ϑΝΠϧ໊Ͱόʔδϣϯ؅ཧ͢Δͷ͸େมͰ͕͢ɺΑ͘࢖ΘΕ·͢Ͷɻ
  3. Git Basic Usage (JUΛ࠷௿ݶ࢖͏ʹ͸ɺҎԼͷίϚϯυ͕ඞཁͰ͢ɻ ίϚϯυ આ໌ DMPOF ϦϞʔτ͔ΒϩʔΧϧʹϦϙδτϦΛΫϩʔϯ͢Δ BEE ϑΝΠϧΛίϛοτީิʹ௥Ճ͢Δ

    DPNNJU มߋཤྺΛίϛοτͯ͠อଘ͢Δ QVTI ίϛοτΛϦϞʔτϦϙδτϦʹૹΔ QVMM ଞਓͷ ίϛοτΛϦϞʔτϦϙδτϦ͔Βऔಘ͢Δ
  4. Version Control - Github Tutorial (JUIVCDPNͰϦϙδτϦΛ࡞੒ͯ͠ɺϦϞʔτϦϙδτϦͱͯ͠ར༻͠·͢ɻ  ΞΧ΢ϯτ࡞੒  ϦϙδτϦ࡞੒

     ʮ3FQPTJUPSZOBNFʯΛೖྗ  ʮ*OJUJBMJ[FUIJTSFQPTJUPSZXJUIB3&"%.&ʯʹνΣοΫ  ʮ$SFBUFSFQPTJUPSZʯΛΫϦοΫ ϦϙδτϦ࡞੒खॱ ը໘ӈ্ΑΓʣ ͔͜͜Β ৄ͘͠͸σϞͰʂ
  5. Version Control - Github Tutorial ϩʔΧϧϦϙδτϦͰ࡞ۀΛͯ͠ɺϦϞʔτϦϙδτϦʹ൓ө͠·͢ɻ # Clone $ git

    clone https://github.com/yoheiMune/my-repo.git # Working anything… $ echo “My first git working.” > my.txt # Add $ git add my.txt # Commit $ git commit -m “ॳΊͯͷίϛοτͩΑʔ” # Push $ git push (6*πʔϧ͋Γ·͢ʂ
  6. Version Control - Github Tutorial # Pull $ git pull

    # Check. $ echo my.txt My first git working. !!!!!!!!! มߋ͕औΓࠐ·Εͨʂ (JUIVC্ͰฤूΛͯ͠ɺͦΕΛ1VMMͯ͠ϩʔΧϧϦϙδτϦʹऔΓࠐΈ·͢ɻ
  7. Version Control - ԋश1 ͜͜·Ͱͷ಺༰Λɺ࣮ࡍʹ΍ͬͯΈ·͠ΐ͏ʂ  (JUIVCͰϦϙδτϦΛ࡞੒͢Δ  4PVSDF5SFFΛΠϯετʔϧ͢Δ 

    ϦϞʔτϦϙδτϦ͔Β$MPOF͢Δ  ৽نϑΝΠϧΛ࡞੒͢Δ  "EE $PNNJU 1VTIΛߦ͍ɺ(JUIVC্ͰมߋΛ֬ೝ͢Δ  (JUIVC্ͰϑΝΠϧΛมߋ͠ɺ1VMMͯ͠ϩʔΧϧʹऔΓࠐΉ
  8. Version Control - Conflict ࣗ෼ͷมߋΛϦϞʔτϦϙδτϦʹ1VTI͠Α͏ͱͨ͠ΒɺΤϥʔʹͳΓ·ͨ͠ɻ ʢ1VTIલʹϦϞʔτϦϙδτϦͷ࠷৽ΛϩʔΧϧʹऔΓࠐΉඞཁ͕͋Γ·͢ʣ # Push => ERROR!!!

    $ git push To github.com:yoheiMune/my-repo.git ! [rejected] master -> master (fetch first) error: failed to push some refs to '[email protected]:yoheiMune/my-repo.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
  9. Version Control - Conflict ͱ͍͏͜ͱͰɺ1VMMίϚϯυͰϦϞʔτϦϙδτϦͷ಺༰ΛऔΓࠐΈ·͢ɻ ͢ΔͱɺίϯϑϦΫτൃੜʂʂ # Pull => Conflict

    $ git pull remote: Counting objects: 3, done. remote: Compressing objects: 100% (3/3), done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), done. From github.com:yoheiMune/my-repo 7a0420e..6fc6c76 master -> origin/master Auto-merging index.html CONFLICT (content): Merge conflict in index.html Automatic merge failed; fix conflicts and then commit the result.
  10. Version Control - Conflict ίϯϑϦΫτ͕ൃੜͨ͠JOEFYIUNMΛ։͍ͯ֬ೝͯ͠Έ·͢ɻ <html> <body> <p> <<<<<<< HEAD

    <strong>Welcome to G's Academy Tokyo!</strong> ======= Welcome to G's Academy Osaka! >>>>>>> 6fc6c76545d9456fb52a5d2e609805233ffa719a </p> </body> </html>
  11. Version Control - Conflict ίϯϑϦΫτ͕ൃੜͨ͠JOEFYIUNMΛ։͍ͯ֬ೝͯ͠Έ·͢ɻ <html> <body> <p> <<<<<<< HEAD

    <strong>Welcome to G's Academy Tokyo!</strong> ======= Welcome to G's Academy Osaka! >>>>>>> 6fc6c76545d9456fb52a5d2e609805233ffa719a </p> </body> </html>
  12. Version Control - Conflict मਖ਼ޙʹɺ"EEˠ$PNNJUˠ1VTIͰϦϞʔτϦϙδτϦʹ൓ө͠·͢ɻ # Add to staging. $

    git add index.html # Commit $ git commit -m “Merge conflict.” # Push $ git push
  13. Version Control - Branches and Pull Requests ϒϥϯνΛ࢖ͬͨ։ൃͷྲྀΕ͸ɺҎԼͷ௨ΓͰ͢ʢҰྫͰ͢ʣɻ  ϦϞʔτϦϙδτϦͰϒϥϯνΛ࡞੒͢Δ

     ϩʔΧϧϦϙδτϦʹ࡞੒ͨ͠ϒϥϯνΛऔΓࠐΉ  ௥ՃػೳͳͲΛ։ൃ͠ɺదٓϒϥϯνʹ$PNNJU͢Δ  ϩʔΧϧ͔ΒϦϞʔτϦϙδτϦʹ1VTI͢Δ  1VMM3FRVFTUΛ࡞੒͢Δ  ୭͔͕ϨϏϡʔ͢Δ  1VMM3FRVFTUΛϚʔδ͢Δ ˞ͱ͸ٯͰ΋໰୊͋Γ·ͤΜ
  14. Version Control - Branches and Pull Requests ϩʔΧϧϦϙδτϦʹϒϥϯνΛऔΓࠐΈ·͢ # Fetch

    remote repository’s updates. $ git fetch # Remote branches list. $ git branch -r origin/HEAD -> origin/master origin/feature/special-link origin/master # Create a local branch via remote. $ git checkout -b feature/special-link origin/feature/special-link
  15. Version Control - Branches and Pull Requests ௥ՃػೳΛ։ൃ͠ɺϒϥϯνʹదٓίϛοτ͠·͢ɻ # Developing…

    $ do something # Add and commit to the branch $ git add . $ git commit -m “Add a special link.”
  16. Version Control - ԋश3 ϒϥϯνΛ࢖ͬͨ։ൃͷྲྀΕΛମݧͯ͠ΈΑ͏ʂ  ϦϞʔτϦϙδτϦͰϒϥϯνΛ࡞੒͢Δ  ϩʔΧϧϦϙδτϦʹ࡞੒ͨ͠ϒϥϯνΛऔΓࠐΉ 

    ௥ՃػೳͳͲΛ։ൃ͠ɺదٓϒϥϯνʹ$PNNJU͢Δ  ϩʔΧϧ͔ΒϦϞʔτϦϙδτϦʹ1VTI͢Δ  1VMM3FRVFTUΛ࡞੒͢Δ  ୭͔͕ϨϏϡʔ͢Δ  1VMM3FRVFTUΛϚʔδ͢Δ
  17. Advanced  (JUIVCؔ࿈ w *TTVFػೳΛ༻͍ͯɺλεΫ؅ཧ΍՝୊؅ཧΛߦ͏ w 1SPKFDUػೳΛ༻͍ͯɺεΫϥϜ։ൃͷΧϯόϯΛ࣮ݱ͢Δ w 'PSLػೳΛ༻͍ͯɺॻ͖ࠐΈݖݶͷͳ͍ϦϙδτϦʹमਖ਼ϦΫΤετΛ౤͛Δ w

    ΦʔΨχθʔγϣϯػೳΛ༻͍ͯɺϦϙδτϦΛ૊৫Ͱ؅ཧ͢Δ w ίϥϘϨʔλʔઃఆΛ༻͍ͯɺϦϙδτϦʹڞಉฤूऀΛ௥Ճ͢Δ w (JTUػೳͰɺίʔυΛͪΐͬ͜ͱॻ͍ͯެ։Ͱ͖Δ w (JUIVC1BHFػೳͰɺ8FCϖʔδΛެ։Ͱ͖Δ ࠓճઆ໌͠ͳ͔ͬͨҎԼ΋ɺΑ͘࢖ΘΕ·͢  (JUؔ࿈ w HJUJHOPSFϑΝΠϧΛ༻͍ͯɺόʔδϣϯ؅ཧର৅֎Λࢦఆ͢Δ w TUBTIػೳΛ༻͍ͯɺະίϛοτͷมߋΛୀආ͢Δ w TVCNPEVMFػೳΛ༻͍ͯɺϦϙδτϦ಺ʹଞͷϦϙδτϦΛಋೖ͢Δ w UBHػೳΛ༻͍ͯɺมߋ஍఺΍ϦϦʔε஍఺Λอଘ͢Δ w ͳͲ
  18. Summary ֶΜͰ͖ͨ͜ͱ w όʔδϣϯ؅ཧͱ͸ w (JUͷ࢖͍ํ w (JUIVCͷ࢖͍ํ w ίϯϑϦΫτͷղফ

    w ϒϥϯν։ൃͱϓϧϦΫΤετ ࠓޙ΁ͷΞυόΠε w (JU(JUIVC͸ඇৗʹศརͳͷͰɺগͣͭ͠׳ΕΔͱྑ͍Ͱ͢ w ίϯϑϦΫτͷղফ͸େมͰ͕͢ɺࣗ෼ͰؤுΓ͗͢ͳ͍͜ͱ͕ϙΠϯτͰ͢ w (JU͸λʔϛφϧͳͲίϚϯυͰ࢖͑Δͱඇৗʹߴ଎ʹ࢖͑·͢