แทนที่จะทำ:
git push origin --all && git push nodester --all && git push duostack --all
มีวิธีทำอย่างนั้นเพียงคำสั่งเดียว?
ขอบคุณ :)
allรีโมตเพื่อผลักดันรีโมตทั้งหมดของคุณโปรดดู: stackoverflow.com/a/18637593/802365
แทนที่จะทำ:
git push origin --all && git push nodester --all && git push duostack --all
มีวิธีทำอย่างนั้นเพียงคำสั่งเดียว?
ขอบคุณ :)
allรีโมตเพื่อผลักดันรีโมตทั้งหมดของคุณโปรดดู: stackoverflow.com/a/18637593/802365
คำตอบ:
git remote | xargs -L1 git push --all
แทนที่masterด้วยสาขาที่คุณต้องการผลักดัน
git remote | xargs -L1 -I R git push R master
git config --global alias.pushall '!git remote | xargs -L1 git push --all'
การทำงานgit pushallจะผลักสาขาทั้งหมดไปยังรีโมททั้งหมด
xargs: illegal option -- lใช้ OSX ได้ คิดออกคุณจะต้องgit remote | xargs -L1 git push
man xargsบอกว่าตัวเลือก-lถูกคัดออกเนื่องจากไม่ได้อยู่ในข้อมูลจำเพาะ POISX
!หมายถึงสิ่งต่อไปนี้ไม่ใช่คำสั่ง git ภายใน แต่เป็นคำสั่งเชลล์ภายนอก
สร้างallรีโมตที่มี repo URL หลายรายการเป็นชื่อ:
git remote add all origin-host:path/proj.git
git remote set-url --add all nodester-host:path/proj.git
git remote set-url --add all duostack-host:path/proj.git
git push all --allแล้วก็
นี่คือลักษณะที่ปรากฏใน.git/config:
[remote "all"]
url = origin-host:path/proj.git
url = nodester-host:path/proj.git
url = duostack-host:path/proj.git
git fetch --allทันทีหลังจากกดปุ่มดังกล่าว
allรีโมตเมื่อพร้อมใช้งานในขณะที่git remote | xargs -L1 git push --allจะรับรีโมตใหม่โดยอัตโนมัติ
allเมื่อใดก็ตามที่คุณส่งคำสั่งซื้อให้ใช้ "ต้นทาง" แทน "ทั้งหมด":git remote set-url --add origin nodester-host:path/proj.git
git pushจะไม่อัปเดต URL ทั้งหมด คำตอบอัปเดตตามนั้น
หากคุณต้องการผลักไปที่ repo1, repo2 และ repo3 เสมอ แต่ดึงจาก repo1 เท่านั้นให้ตั้งค่า 'ต้นกำเนิด' ระยะไกลเป็น
[remote "origin"]
url = https://exampleuser@example.com/path/to/repo1
pushurl = https://exampleuser@example.com/path/to/repo1
pushurl = https://exampleuser@example.com/path/to/repo2
pushurl = https://exampleuser@example.com/path/to/repo3
fetch = +refs/heads/*:refs/remotes/origin/*
กำหนดค่าที่บรรทัดคำสั่ง:
$ git remote add origin https://exampleuser@example.com/path/to/repo1
$ git remote set-url --push --add origin https://exampleuser@example.com/path/to/repo1
$ git remote set-url --push --add origin https://exampleuser@example.com/path/to/repo2
$ git remote set-url --push --add origin https://exampleuser@example.com/path/to/repo3
ถ้าคุณเพียงต้องการที่จะดึงจากrepo1แต่ดันrepo1และrepo2 สาขาที่เฉพาะเจาะจงspecialBranch :
[remote "origin"]
url = ssh://git@aaa.xxx.com:7999/yyy/repo1.git
fetch = +refs/heads/*:refs/remotes/origin/*
...
[remote "specialRemote"]
url = ssh://git@aaa.xxx.com:7999/yyy/repo1.git
pushurl = ssh://git@aaa.xxx.com:7999/yyy/repo1.git
pushurl = ssh://git@aaa.xxx.com:7999/yyy/repo2.git
fetch = +refs/heads/*:refs/remotes/origin/*
...
[branch "specialBranch"]
remote = origin
pushRemote = specialRemote
...
ดูhttps://git-scm.com/docs/git-config#git-config-branchltnamegtremote
git pushโดยไม่มีข้อโต้แย้งใด ๆ
ในฐานะที่เป็นทางเลือก CLI สำหรับแก้ไขไฟล์. git / config คุณสามารถใช้คำสั่งต่อไปนี้:
# git remote add all origin-host:path/proj.git
# git remote set-url --add all nodester-host:path/proj.git
# git remote set-url --add all duostack-host:path/proj.git
git push all --allงานเดียวกันที่นี่เช่นกัน
คุณทำแบบเดียวกันกับคำตอบ # 1 คุณเพิ่งทำมาพร้อมกับ Command Line แทนการแก้ไขไฟล์ config
ฉันเขียนฟังก์ชั่นทุบตีสั้น ๆ เพื่อผลักดันรีโมตจำนวนมากในการโทรครั้งเดียว คุณสามารถระบุรีโมตเดี่ยวเป็นพารามิเตอร์หลายรีโมตคั่นด้วยช่องว่างหรือไม่ระบุใด ๆ เพื่อให้รีโมตไปที่รีโมตทั้งหมด
สามารถเพิ่มลงใน. bashrc หรือ. bash_profile ของคุณ
function GitPush {
REMOTES=$@
# If no remotes were passed in, push to all remotes.
if [[ -z "$REMOTES" ]]; then
REM=`git remote`
# Break the remotes into an array
REMOTES=$(echo $REM | tr " " "\n")
fi
# Iterate through the array, pushing to each remote
for R in $REMOTES; do
echo "Pushing to $R..."
git push $R
done
}
ตัวอย่าง: สมมุติว่า repo ของคุณมี 3 รีโมท: rem1, rem2 และ rem3
# Pushes to rem1
GitPush rem1
# Pushes to rem1 and rem2
GitPush rem1 rem2
# Pushes to rem1, rem2 and rem3
GitPush
คุณสามารถใช้ตะขอคอมไพล์ - โดยเฉพาะอย่างยิ่งpre-push: .git/hooks/pre-pushเพิ่มดันไม่ใช่ต้นทางไปยัง