clone & push all remote branches with git

本文提供了一个简洁的Shell脚本,用于从Git仓库中克隆所有远程分支,并将这些分支推送到本地及指定URL,包括跳过master分支的克隆和推送过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Assuming you have a GIT repository with many branches, it might be little daunting to checkout all the branches as local. This question was also asked in StackOverflow here. This nifty shell script does the job to clone all remote branches locally.


for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master`; do git branch --track ${branch##*/} $branch; done


It will create tracking branches for all remote branches, except master (which you probably got from the original clone command). You might still need to do a -


git fetch --all 
git pull --all


To push all the branches including master -


push to another url
git remote add ALIAS USERNAME@IP-ADDRESS:/PATH/REPO.git
git push ALIAS --all 


push to origin url
git push --all


http://thoughtpad.cs3.in/2011/06/13/clone-push-all-remote-branches-with-git/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值