git branch -r
ส่วนใหญ่คำตอบที่นี่มีมากกว่าแทรกซ้อนแยกของการส่งออกของ คุณสามารถใช้for
วงต่อไปนี้เพื่อสร้างสาขาการติดตามกับทุกสาขาในระยะไกลเช่นนี้
ตัวอย่าง
บอกว่าฉันมีสาขาระยะไกลเหล่านี้
$ git branch -r
origin/HEAD -> origin/master
origin/development
origin/integration
origin/master
origin/production
origin/staging
ยืนยันว่าเราไม่ได้ติดตามสิ่งอื่นนอกจากต้นแบบแล้วภายในเครื่อง:
$ git branch -l # or using just git branch
* master
คุณสามารถใช้สายการบินเดียวนี้เพื่อสร้างสาขาการติดตาม:
$ for i in $(git branch -r | grep -vE "HEAD|master"); do
git branch --track ${i#*/} $i; done
Branch development set up to track remote branch development from origin.
Branch integration set up to track remote branch integration from origin.
Branch production set up to track remote branch production from origin.
Branch staging set up to track remote branch staging from origin.
ตอนนี้ยืนยัน:
$ git branch
development
integration
* master
production
staging
หากต้องการลบ:
$ git br -D production development integration staging
Deleted branch production (was xxxxx).
Deleted branch development (was xxxxx).
Deleted branch integration (was xxxxx).
Deleted branch staging (was xxxxx).
หากคุณใช้-vv
สวิตช์ให้git branch
คุณสามารถยืนยัน:
$ git br -vv
development xxxxx [origin/development] commit log msg ....
integration xxxxx [origin/integration] commit log msg ....
* master xxxxx [origin/master] commit log msg ....
production xxxxx [origin/production] commit log msg ....
staging xxxxx [origin/staging] commit log msg ....
พังทลายของวง
ห่วงโดยทั่วไปเรียกคำสั่งกรองออกหัวหรือปริญญาโททุกสาขาในการส่งออกโดยใช้git branch -r
grep -vE "HEAD|master"
ที่จะได้รับชื่อเพียงสาขาลบorigin/
substring ${var#stringtoremove}
เราใช้การจัดการสตริงทุบตีของ นี้จะลบสตริง "stringtoremove" $var
จากตัวแปร ในกรณีที่เราจะลบสตริงจากตัวแปรorigin/
$i
หมายเหตุ:หรือคุณสามารถใช้git checkout --track ...
เพื่อทำสิ่งนี้เช่นกัน:
$ for i in $(git branch -r | grep -vE "HEAD|master" | sed 's/^[ ]\+//'); do
git checkout --track $i; done
แต่ฉันไม่สนใจวิธีนี้เป็นพิเศษเพราะมันสลับคุณไปมาระหว่างสาขาเพราะมันเช็คเอาท์ เมื่อเสร็จแล้วมันจะทำให้คุณอยู่ในสาขาสุดท้ายที่มันสร้างขึ้น
อ้างอิง
git checkout --track origin/branchname