Tag: git

  • [บันทึกกันลืม] แก้ปัญหา server certificate verification failed บน gitlabs

    ปัญหาคือ: จะ git push จาก Linux/Ubuntu มาเก็บใน gitlabs ขององค์กร

    git push -u origin master

    แต่ติดปัญหาว่า

    fatal: unable to access 'https://gitlab.xxx.xxx.xxxx/userid/repo.git/': server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none

    วิธีแก้ปัญหา (แบบรีบ ๆ)

    git config --global http.sslVerify false

    ก็จะใช้งานได้แล้ว

    *** เออ “ก็ง่าย ๆ” แต่ไม่มีบอกไว้ให้หาง่าย ๆ นิ ***

  • วิธีการใช้ Google Drive เป็น Private Git Repository

    git คือ distributed revision control system

    เรามักใช้ github.com สำหรับเก็บ source code แต่มัน public ซึ่ง บางทีเราก็ต้องการอะไรที่ private

    ต่อไปนี้ คือวิธีการใช้งาน Google Drive เพื่อสร้าง Private Git Repository

    1. ติดตั้ง Google Drive File Stream, git ให้เรียบร้อย
    2. ใน Google Drive สร้าง Directory ชื่อ git ขึ้นมาที่ My Drive
      กรณี Google Drive File Stream ก็จะเห็นที่
      G:\My Drive\git
    3. จากนั้น ก็สร้าง Working Directory  เช่น ที่ Documents
      ในภาพ สร้างไว้ใน Documents\firebase\fmsworkshop
      จากนั้น คลิก Git Bash Here
    4. ใช้คำสั่ง
      git init

      เพื่อสร้าง .git ใน Directory นี้ก่อน
      จากนั้นใช้คำสั่งนี้ ที่มี –bare เพื่อสร้าง Remore Repository บน Google Drive

      git init --bare "G:\My Drive\git\fmsworkshop.git"

    5. บน Google Drive File Stream ก็จะมี fmsworkshop.git ปรากฏขึ้น
      ซึ่งต่อไปก็สามารถ git push ขึ้นไปเก็บไว้ได้แล้ว
    6. ต่อไป ก็พัฒนาโปรแกรมไป
    7. แล้ว ก็ git push ตามปรกติครับ
      git add .
      git commit -m "some text"
      git push "G:\My Drive\git\fmsworkshop.git"

    หวังว่าจะเป็นประโยชน์ครับ

  • การใช้ GitHub Command Line #newbie

    Prerequisite

    • ต้องมี GitHub Account ก่อน ทำตามวิธีการนี้ https://help.github.com/articles/signing-up-for-a-new-github-account/
    • สร้าง GitHub Repository บน Web ก่อน  (ในที่นี้ จะสร้าง Repository ชื่อ mynewrepo) ซึ่งจะได้ URL มาเป็น https://github.com/your-username/mynewrepo.git

    สร้าง local repository

    mkdir mynewrepo
    cd mynewrepo
    git init
    git status

    สร้างไฟล์ใหม่

    # สมมุติสร้างไฟล์ใหม่
    echo "Hello World" > mynewfile.txt
    git add .
    git status

    ทำการ Commit

    git commit -m "This is a first Commit"

    สร้าง Connection ระหว่าง Local Folder กับ GitHub Repository

    git remote add origin https://github.com/your-username/mynewrepo.git
    git push -u origin master

    จากนั้น ใส่ Username/Password ของ GitHub Account

    ไปดูผลงานใน Repository “mynewrepo” ที่ https://github.com/your-username/mynewrepo

    เมื่อมีการแก้ไขไฟล์

    echo "Hello New World" >> mynewfile.txt
    git status

    ทำการ เพิ่ม > Commit > Push

    git add .
    git commit -m "This is a second Commit"
    git push -u origin master

    วนไป

     

  • เชื่อมต่อ GitHub Repository ด้วย Visual Studio 2015

    ในการพัฒนาแอปพลิเคชันหรือระบบงานหนึ่งขึ้นมา การจัดการ File source code ไม่ว่าจะเป็นการสร้าง การแก้ไข การควบคุม file version ต่างๆ ถือเป็นเรื่องสำคัญ ซึ่งในบทความนี้นำเสนอการใช้งาน Visual Studio 2015 ในการเชื่อมต่อไปยัง GitHub Server

    Git คือ Version Control ตัวหนึ่ง มีหน้าที่ในการจัดเก็บการเปลี่ยนแปลงของ file source code มีการ backup code ให้เรา สามารถที่จะเรียกดูหรือย้อนกลับไปดูเวอร์ชั่นต่างๆของ project เรา รวมถึงสามารถ track ได้ว่าไฟล์นั้นๆใครเป็นคนเพิ่มหรือแก้ไข ถูกสร้างโดยใคร ถูกปรับปรุงโดยใคร

    GitHub คือ web open source ที่ให้บริการพื้นที่จัดเก็บ source code ของ project ที่เราได้พัฒนา โดยมีระบบควบคุม (version control) แบบ Git ซึ่งทำให้การพัฒนา project ต่างๆ สามารถแชร์ file source code ได้ง่ายขึ้น

     

    เครื่องมือที่ใช้ในการเชื่อมต่อ GitHub Repository ด้วย Visual Studio 2015

    1. Microsoft Visual Studio 2015
    2. GitHub Extension for Visual Studio สามารถ download ได้จาก link ของ github โดยตรง >> Download Now 
    3. Account ที่ใช้ในการเข้าถึง web GitHub

     

    ขั้นตอนการเชื่อมต่อ GitHub Repository ด้วย Visual Studio 2015

    1.ติดตั้ง GitHub Extension for Visual Studio ที่ได้ดาวน์โหลดจากลิงค์ข้างบน

    install1

    2. เมื่อติดตั้งเสร็จจะขึ้นดังรูป

    install2

    3.เปิด Visual Studio 2015 ขึ้นมา ไปยังแท็บ Team Explorer แล้วกด Manage Connections ที่ไอคอนรูปปลั๊ก ดังรูป

    connect

    4.ที่เมนู GitHub ให้คลิก Login

    image4

    5.กรอกข้อมูล GitHub Account ที่จะเชื่อมต่อ แล้วกดปุ่ม Login

    filllogin

    6.เมื่อ Login สำเร็จ จะแสดง GitHub repository ทั้งบน GitHub server และ repository บนเครื่อง local ของเราเองดังรูป

    displayrepo

    7.เข้าไปที่ https://github.com/ แล้ว Login ด้วย GitHub Account ของเราแล้วไป tab>> Repository เพื่อสร้าง Repository ที่จะเก็บ Project ที่เราต้องการจะเพิ่มเข้าไปจาก Visual Studio โดยกรอก repository name และกดปุ่ม Create repository

    newrepo

    8. เราจะได้ repository เปล่าๆ ที่เราสร้างขึ้นดังรูป

    empty repository

    9. เปิด project ที่ต้องการเพิ่มเข้า repository ขึ้นมา คลิกขวาที่ solution เลือก add solution to source control ดังรูป

    addTorepo

    10.จะปรากฎหน้าต่างให้เราเลือก Source Control ที่เราเลือก Git แล้วกดปุ่ม OK

    choosesource

     

    11.ให้เรากรอก Commit Message เสร็จแล้วให้เลือกไปที่ commit ซึ่งจะมีตัวเลือกการ commit หลายแบบ ได้แก่ Commit, Commit and Push และ Commit and Sync ในที่่นี่ผู้เขียนเลือก Commit and Push ซึ่งเป็นการ commit และโยน file source code ขึ้นไปยัง web server repository ด้วย เพื่อแสดงให้ผู้อ่านเห็นว่ามีการเชื่อมต่อกันแล้วจริง

    commitmsg

    12. หลังจากกด Commit and Push จะมี message แจ้งเตือนว่า “There is no remote repository configured. Publish this repository to share your commits.” ซึ่งหมายถึงเรายังไม่ระบุและ reomte ไปยัง repository ที่เราต้องการจะเพิ่ม ให้เราเลื่อนมาด้านล่างและระบุ url ของ repository ที่เราได้สร้างไว้ก่อนหน้านี้บน web GitHub แล้วกดปุ่ม Publish ดังรูป

    publish repo

    13. เมื่อกดปุ่ม Publish รอจนเสร็จสิ้นแล้วจะปรากฎหน้าต่าง ดังรูป

    finish

    ให้คลิกมาที่แท็บ Solution Explorer จะสังเกตุเห็นว่าไฟล์แต่ละไฟล์จะมีรูปกุญแจแล้ว แสดงว่า file source code ของเราถูกเพิ่มเข้า Git source control เรียบร้อยแล้ว

    lock

    14. กลับไปที่เว็บไซต์ GitHub แล้วไปยัง repository ที่เราได้สร้างและเพิ่ม project จาก Visual Studio เข้าไป จะปรากฎ File source code ที่เรา Commit and Push มาจาก Visual Studio แล้ว

    finishRepo1

    finishRepo2

     

    เป็นอันเสร็จสิ้นการเชื่อมต่อและเพิ่ม project เข้าไปยัง GitHub Repository ด้วย Visual Studio 2015 แล้วค่ะ ^^

     

    แหล่งข้อมูลอ้างอิง : https://visualstudio.github.com/

  • Short Note on Workshop “Web Application Development Workflow”

    ผมชวนเพื่อนๆ CoP PSU IT ซึ่งเป็นรุ่นน้องชื่อคุณราชศักดิ์ บูรณะพาณิชย์กิจ และพัฒนาวดี ศิวติณฑุโก อยู่ที่คณะวิศวกรรมศาสตร์ มาจัด Workshop ใช้เวลา 1 วัน เรื่อง Web Application Development Workflow
    git.6

    วิทยากรเตรียม slide ที่นี้ครับ http://bratchasak.github.io/slide/
    คร่าวๆ คือ แนะว่า Web Application Development Workflow คืออะไร อธิบายว่าขั้นตอนของการพัฒนาและเครื่องมือที่ใช้ในการทำงาน ก็คือ Chrome Browser และ Sublime Text และติดตั้งโปรแกรม Git ใช้งานแบบ command line และ github for Windows แบบ GUI และสมัครบริการที่จำเป็นต้องใช้ก็คือ GitHub web เครื่องมือทั้งหมดนี้ก็จะสร้างระบบ Version control สำหรับการพัฒนาด้วย Git ได้แล้ว

    การเตรียมเครื่องมือสำหรับทำงาน
    1.เกี่ยวกับ Chrome Browser (google chrome)
    ต้องลงชื่อเข้าใช้ google เพื่อทำงานได้ครบทุก Feature
    เข้าเว็บหน้านี้ https://www.google.com/intl/th/chrome/browser/ จะเห็นตัวอย่างชัดๆในการตรวจสอบด้วย Developper Tools
    เปิดหน้าต่าง Developper Tool ด้วย Ctrl+Shift+i
    คลิกเลือกไอคอน แว่นขยาย เพื่อส่องดูโค้ดได้
    นอกจากนี้ก็มีแท็บน่าสนใจคือ แท็บ Console สำหรับ debug และ แท็บ Network สำหรับดู latency load time

    เปิดดูการทำงาน เมนูที่ใช้ใน workshop คือ คลิกปุ่มกำหนดค่าและควบคุม (มุมบนขวา) > เครื่องมือ > ตัวจัดการงาน

    ติดตั้งส่วนขยาย LiveReload
    www.google.com > search คำว่า livereload > เลือก Chrome Web Store – LiveReload
    คลิกปุ่มกำหนดค่าและควบคุม (มุมบนขวา) > เครื่องมือ > ส่วนขยาย > เลือกตัวเลือก อนุญาตให้เข้าถึงไฟล์ URL

    2. ติดตั้งโปรแกรม Sublime Text 3 for Windows
    git.5
    www.google.com > search คำว่า sublime
    เลือกเวอร์ชั่นให้ตรงกับ Windows OS ที่ใช้
    ตาม slide หน้านี้ http://bratchasak.github.io/slide/#sublimetext_package

    ติดตั้ง package เพิ่มลงใน Sublime
    กดแป้น Ctrl+Shift+p > search คำว่า package > เลือก Package Control: Install Package
    > search คำว่า emmet > คลิกเลือก emmet
    > search คำว่า livereload > คลิกเลือก LiveReload
    > search คำว่า syntax คลิกเลือก Syntax Manager

    ต่อมา วิทยากรอธิบาย Software configuration management ว่ามี 3 model คือ Local data model, Client-server model และ Distributed model เช่น Git
    “Git is a free and open source distributed version control system.”
    git.2

    3. ติดตั้ง Git
    เข้าไปเว็บไซต์ http://git-scm.com/ และดาวน์โหลดเวอร์ชั่นสำหรับวินโดวส์ จะได้ไฟล์ Git-1.9.0-preview20140217.exe
    คลิก Run เพื่อติดตั้ง แต่ไม่คลิก Next ทั้งหมด
    ในหน้า Select Components เลือก Simple context menu
    ในหน้า Adjusting your PATH environment เลือก Run Git from the Windows Command Prompt
    ในหน้า Configuring the line ending conversions เลือก Checkout Windows-style,commit Unix-style line endings

    ต่อจากนั้น วิทยากรอธิบายเกี่ยวกับ Git – File Status Lifecycle
    ดูที่ http://bratchasak.github.io/slide/#gitstatus
    git.1

    เริ่มต้นเข้าสู่การใช้งาน Git
    แบบที่ 1 เรียนรู้การทำงานในแบบ command line
    สร้างโฟลเดอร์ที่จะเป็น Repository (ก็คือ project)
    คลิกปุ่ม Start > พิมพ์ cmd
    cd \
    mkdir test
    cd test
    git init
    จะเกิดโฟลเดอร์ชื่อ .git

    ตรวจสอบสถานะ
    git status

    เริ่มต้นด้วยการกำหนดชื่อ identity เจ้าของ repository
    git config –global user.name “Wiboon Warasittichai”
    git config –global user.email “wiboon080808@gmail.com”

    ตรวจสอบรายการในไฟล์ config
    git config –list

    นำไฟล์ index.html เข้าใน project หรือเรียกว่า repository
    git add index.html

    เปลี่ยนเข้าสู่สถานะ staged
    git commit -m “initial commit”

    ตรวจดูรายการแก้ไข
    git log
    หรือ
    แสดงผลแบบ 1 บรรทัดพร้อมด้วยตัวชี้(pointer)
    git log –graph –decorate –all –pretty –oneline

    การแตก branch เพื่อใช้ทำงานเขียนโปรแกรม แทนการแก้ไขที่ master
    git branch feat_test

    เข้าแก้ไขใน branch
    git checkout feat_test

    เปิดหน้า sublime แล้วลองเพิ่ม 1 บรรทัดลงใน index.html

    ต่อไปทำซ้ำรอบในการทำงาน คือนำไฟล์ index.html เข้าใน project (จะเรียกว่า repository)
    git add index.html

    เปลี่ยนเข้าสู่สถานะ staged อีกครั้งแต่รอบนี้เป็นการแก้ไขที่ branch
    git commit -m “1st edit – add 1 line”

    แสดงผลแบบ 1 บรรทัดพร้อมด้วยตัวชี้(pointer)จะเห็นว่า pointer อยู่ที่ branch ชื่อ feat_test
    git log –graph –decorate –all –pretty –oneline

    กลับไปที่ master
    git checkout master

    ดูที่ sublime text editor จะเห็นว่าเป็น index.html ก่อนการเพิ่มอีก 1 บรรทัด
    (แสดงผลที่แตกต่างทันทีจากที่เพิ่ม package ชื่อ LiveReload ลงใน sublime text)

    ต้องการ merge ไฟล์ index.html ของ branch ชื่อ feat_test เข้ากับ branch ชื่อ master
    git merge feat_test

    ตรวจสอบสถานะ
    git status

    สมัครสมาชิก GitHub web เพื่อใช้เป็นที่เก็บ repository ของเราเพื่อเผยแพร่สาธารณะ
    เข้าไปที่ https://github.com/
    git.3

    แบบที่ 2 เรียนรู้การใช้งาน Git แบบ GUI
    git.4
    ต่อไปจะเป็นการใช้ GitHub for Windows (เรียกว่า Client) ให้ดาวน์โหลดที่นี่ http://windows.github.com
    ติดตั้งใช้เวลานิดนึง เพราะไฟล์ขนาด 41.8MB เมื่อเสร็จจะมีหน้าต่าง Welcome เพื่อให้ login
    ก็ใส่ e-mail และ password ที่สมัคร
    ต่อไปจะอยู่ที่ขั้นตอน configure ให้คลิก Next
    อยู่ที่ขั้นตอน repositories ให้คลิก dashboard
    จะเปิดหน้าต่าง ให้เราลาก โฟลเดอร์ชื่อ test มาใส่ที่ local – repositories
    แล้วคลิกลูกศรชี้ขวาที่บรรทัด test จะเป็นคำว่า Open this repo
    คลิก publish
    เมื่อมีการแก้ไข branch master หรือ branch feat_test ก็คลิก Sync

    ในทางกลับกัน หากสร้าง repository จากหน้า GitHub web ก็สามารถ clone ลงไปที่ Windows ได้เช่นกัน
    กลับไปที่ GitHub web โดยเข้าไปที่ https://github.com/
    คลิก New repository
    ตั้งชื่อ Repository name ตั้งว่า ztest แล้วคลิก Create repository
    คลิกปุ่ม Set up in Desktop มันจะมาสร้างไดเรกทอรีที่ c:\My Documents\GitHub\ztest
    Google chrome จะถามอะไรสักอย่าง ก็ให้ตอบ “เปิดใช้งานแอปพลิเคชัน”
    เราก็เริ่มทดสอบสร้างไฟล์ my.html ไว้ที่นี่ แล้ว publish กลับไปที่ GitHub web ได้เมื่อต้องการ

    เรื่องสุดท้าย GitHub – Features อันแรก Collaborators คือ การอนุญาต user บน GitHub ให้ร่วมแก้ไขไฟล์ด้วยกันได้ และอีกอัน Fork & Pull Request คือ เอาไปทั้งหมดแยกกันไปทำแล้วค่อยมารวม และ GitHub Pages คือ การสร้าง web page บน GitHub

    การสร้าง web page บน GitHub ทำดังนี้
    หากเราสร้าง repository ด้วยการตั้งชื่อด้วยข้อความ username.github.io ก็จะได้ web page ไว้ใช้งานด้วย
    ซึ่งสร้างอย่างง่ายๆด้วย Automatic Page Generator (https://help.github.com/articles/creating-pages-with-the-automatic-generator) หลังจากสร้างเสร็จต้องรอ 10 นาที web page ก็จะใช้งานได้
    ทดสอบด้วยการพิมพ์ว่า http://username.github.io ตัวอย่างเช่น http://wiboon.github.io/

    ทั้งหมดนี้ผมก็ฟังไปจดไปในกระดาษ แล้วก็กลับมาลองทำเองดูในวันนี้ แล้วก็เขียนลง sysadmin blog ที่นี้ไว้เผื่อเพื่อนๆด้วยครับ