问题描述
随着时间的推移,这些分支和标签会过时。
如何使叉子变得简单,确保叉子具有所有分支和标签而无需reclone?
即一个git magicpull --rebase upstream / * myremote / *
可以获取上游的所有分支和标签,并确保myremote中存在相同的分支和标签。
假设您的上游远程服务器被命名为origin,并且您的用户名下有自定义分支(即maxandersen / p>
当您的克隆运行以下一行时(刷新:
remote = origin;对于`git分支中的brname -r | grep origin | grep -v master | grep -v HEAD | sed -e's /.* \ /// g'`;做git分支 - -track $ brname $ remote / $ brname; done
这将为所有分支设置追踪分支在远程名为'origin'。
如果你已经有了这个branchname结帐它不会(可选)现在确保你所有的分支都是最新的(如果你已经分支出去了,那么这个分支很有用):
git pull --rebase --all
现在,所有分支机构设置为跟踪并向您的远程设备推送分支和标签(用您的远程名称替换maxandersen):
git push --all maxandersen
git push --tags maxandersen
在此之后,您的分支同步。
以下脚本包含要求确认的所有内容:
##检出来自远程的所有分支作为跟踪分支。基于https://stackoverflow.com/questions/379081/track-all-remote-git-branches-as-local-branches/6300386#6300386
UPSTREAM = $ 1
MYREPO = $ 2
usage(){
echoUsage:
echo$ 0< upstream-remote>< target-remote>
echo
echo确保远程命名的'maxandersen'具有与'origin'相同的所有分支和标签的示例
echo$ 0 origin maxandersen
exit 1
}
如果[-z$ UPSTREAM]
然后
回显缺少上游远程名称。
用法
fi
如果[-z$ MYREPO]
然后
回显缺少目标远程名称。
用法
fi
读-p1.这将设置'$ MYREPO'来跟踪'$ UPSTREAM'中的所有分支 - 你确定吗? -n 1 -r
if [[$ REPLY =〜^ [Yy] $]]
然后
用于`git branch中的brname -r | grep$ UPSTREAM| grep -v master | grep -v HEAD | sed -e's /.* \ /// g'`;做git分支--track $ brname $ UPSTREAM / $ brname; done
fi
read -p2.这会将所有本地分行和标签推送到$ MYREPO - 你确定吗? -n 1 -r
$ b $ if if [[$ REPLY =〜^ [Yy] $]]
然后
git push --all $ MYREPO
git push - -tags $ MYREPO
fi
将其保存为'updateallbranchestags.sh'并将其与:
sh updateallbranches.sh origin maxandersen
来自'origin'的所有分支/标签将在远程名为'maxandersen'中提供
When you fork a repository on github your forked repo contains all branches and tags.
Over time these branches and tags gets outdated.
How does one as easy it is with fork make sure your fork has all branches and tags without having to reclone ?
i.e. a git magicpull --rebase upstream/* myremote/*
which would fetch all the branches and tags in upstream and make sure the same are present in myremote.
This assumes your "upstream" remote is named "origin" and you have your custom fork under your username (i.e. "maxandersen")
When you have your clone run the following one-liner (refresh of Track all remote git branches as local branches :
remote=origin ; for brname in `git branch -r | grep origin | grep -v master | grep -v HEAD | sed -e 's/.*\///g'`; do git branch --track $brname $remote/$brname ; done
This will setup tracking branches for all the branches found in the remote named 'origin'.If you already have a checkout with this branchname it will not change anything except ensure the tracking is in place.
(Optional) Now ensure all your branches are uptodate (useful if you have already branches checked out):
git pull --rebase --all
Now with all branches setup for tracking and uptodate push branches and tags to your remote (replace 'maxandersen' with your remote name):
git push --all maxandersen
git push --tags maxandersen
After this your fork is in sync.
The following script does all this including asking for confirmation:
## Checkout all branches from remote as tracking branches. Based on https://stackoverflow.com/questions/379081/track-all-remote-git-branches-as-local-branches/6300386#6300386
UPSTREAM=$1
MYREPO=$2
usage() {
echo "Usage:"
echo "$0 <upstream-remote> <target-remote>"
echo ""
echo "Example which ensures remote named 'maxandersen' have all the same branches and tags as 'origin'"
echo "$0 origin maxandersen"
exit 1
}
if [ -z "$UPSTREAM" ]
then
echo Missing upstream remote name.
usage
fi
if [ -z "$MYREPO" ]
then
echo Missing target remote name.
usage
fi
read -p "1. This will setup '$MYREPO' to track all branches in '$UPSTREAM' - Are you sure ?" -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
for brname in `git branch -r | grep "$UPSTREAM" | grep -v master | grep -v HEAD | sed -e 's/.*\///g'`; do git branch --track $brname $UPSTREAM/$brname ; done
fi
read -p "2. This will push all local branches and tags into '$MYREPO' - Are you sure ?" -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
git push --all $MYREPO
git push --tags $MYREPO
fi
Save it as 'updateallbranchestags.sh' and execute it with:
sh updateallbranches.sh origin maxandersen
And all branches/tags from 'origin' will be made available in remote named 'maxandersen'
这篇关于如何更新我的叉与github上的原始存储库具有相同的分支和标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!