ผ่านไปแล้ว 2 ตอน เกี่ยวกับ Git วันนี้ขอแนะนำวิธีการตั้งค่า ให้สามารถใช้งานผ่าน Proxy Server กันซักหน่อย
สำหรับใครที่ใช้ Internet ผ่าน Proxy นั้น ก่อนที่จะนำ Repository ไปฝากไว้บน Server ต่าง ๆ ได้ จำเป็นจะต้องตั้งค่า Proxy ให้กับ Git เสียก่อน โดยเราสามารถตั้งค่าให้กับทุก Repository หรือจะตั้งค่าให้กับเฉพาะบาง Repository ก็ได้เช่นกัน รวมไปถึง Proxy ที่ต้องมีการ Authenticate ก็สามารถตั้งค่าได้ด้วย ทั้งหมดนี้ สามารถทำได้ผ่านทาง Command line หรือ Git Bash
List of contents
- Global config
- Local config
- Config proxy server
- Config authenticate proxy server
- View proxy config
- Remove proxy config
Global config
สำหรับการตั้งค่าให้กับทุก Repository นั้น เราจะใช้ คำสั่งดังนี้
1 |
git config --global <variable> |
โดยที่ variable จะเป็นตัวแปรต่าง ๆ ที่เราจะกำหนดค่า
Local config
ส่วนการตั้งค่าให้กับเฉพาะบาง Repository ให้ใช้ Git Bash บน path ของ Repository นั้น ๆ แล้วใช้ คำสั่งดังนี้
1 |
git config --local <variable> |
ซึ่งคำสั่งก็จะคล้ายกับการตั้งค่าให้กับทุก Repository แค่เปลี่ยนจาก –global เป็น –local และอย่าลืมว่า ต้องพิมพ์คำสั่งภายใต้ path ของ Repository ที่จะกำหนด
Config proxy server
สำหรับการตั้งค่า Proxy Server นั้น สามารถกำหนดผ่านตัวแปรชื่อ http.proxy และ https.proxy (แล้วแต่ว่าใช้ Proxy Server ชนิดใด) โดยมี คำสั่งดังนี้
- สำหรับ HTTP Proxy
1 |
git config --global http.proxy <address>:<port> |
- สำหรับ HTTPS Proxy
1 |
git config --global https.proxy <address>:<port> |
Config authenticate proxy server
หาก Proxy Server ต้องทำการ Authenticate ด้วย สามารถตั้งค่าได้ ดังนี้
- สำหรับ HTTP Proxy
1 |
git config --global http.proxy http://<username>:<password>@<address>:<port> |
- สำหรับ HTTPS Proxy
1 |
git config --global https.proxy https://<username>:<password>@<address>:<port> |
View proxy config
สำหรับการดูค่า Proxy ที่กำหนดไปแล้ว สามารถดูได้ด้วยคำสั่ง ดังนี้
- สำหรับ HTTP Proxy
1 |
git config --global http.proxy |
- สำหรับ HTTPS Proxy
1 |
git config --global https.proxy |
Remove proxy config
การลบค่า Proxy ที่กำหนดไว้แล้ว สามารถทำได้ด้วยคำสั่งดังนี้
- สำหรับ HTTP Proxy
1 |
git config --global --unset http.proxy |
- สำหรับ HTTPS Proxy
1 |
git config --global --unset https.proxy |
สำหรับการ Config, View หรือ Remove เฉพาะ Repository ที่ต้องการ ก็แค่เปลี่ยนคำว่า –global เป็น –local นะครับ ที่เหลือเหมือนกันหมดเลย เลยไม่เขียนให้ดูนะ
อธิบายไว้ในหัวข้อ Global config และ Local config ไปแล้วนี่นะ
เท่านี้เราก็สามารถใช้งาน Git ผ่าน Proxy ได้แล้วววววววว~!!