การติดตั้ง Git

เริ่มต้นการใช้งานในครั้งแรก

ubuntu

$ sudo apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \
  libz-dev

$ sudo apt install git

Fedora

$ sudo dnf install git

centos7

$ sudo yum install curl-devel expat-devel gettext-devel \
  openssl-devel zlib-devel

$ sudo yum install git

mac

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install git

windows เปิดเวป และ Download ทำตาม ข้อแนะนำ

https://git-for-windows.github.io/

http://msysgit.github.io/

สิ่งแรกที่ต้องทำคือการตั้งค่าของ username และ email เพราะว่า ทุกครั้งที่มีการ commit จะใช้เป็นข้อมูลในการ Commit

$ git config --global user.name "Sawangpong Muadphet"
$ git confit --global user.email [email protected]

ตรวจค่าที่ตั้งไว้ใน config

$ git config --list

การใช้งาน Help สำหรับการช่วยเหลือ

$ git helo <verb>
$ git <verb> --help
$ man git-<verb>

สร้าง Repository ใหม่

$ mkdir project
$ cd project
$ git init .

Checkout project ที่มีอยู่แล้ว

นอกจากการสร้าง Repository ใหม่แล้ว เรายังสามารถ ทำการ Checkout มาจาก Project ที่มีอยู่แล้วด้วยการใช้คำสั่ง git clone

//copy จาก local repository ในเครื่องตัวเอง
$ git clone /path/to/repository

//copy จาก remote repository 
$ git clone username@host:/path/to/repository

Git Workflow

ใน local repository จะประกอบด้วยโครงสร้างของ file system หรือที่เรียกสั้นๆ ว่า tree อยู่ 3 tree ด้วยกันโดย Git จะทำหน้าที่บริหารจัดการติดตาม file ในโครงสร้างดังกล่าว 3 tree ได้แก่

  1. working directory ทำหน้าที่เก็บไฟล์ที่สามารถใช้งานได้ ที่อยู่ในสถานะปัจจุบัน
  2. Index หรือ Stage เป็น ที่เก็บไฟล์ก่อนที่จะนำไปเก็บใน Repository จริง
  3. HEAD หรือ Repository จริง ทำหน้าที่จัดเก็บ file และ directory ต่างๆ ที่สร้างขั้นในรูปแบบของ object SHA-1

results matching ""

    No results matching ""