当您在github上分叉存储库时,您的分叉存储库包含所有分支和标记.
随着时间的推移,这些分支和标签会过时.
如何使用叉子轻松确保您的叉子具有所有分支和标签而不必重新拼接?
即一个git magicpull --rebase upstream/*myremote/*
它将获取上游的所有分支和标记,并确保myremote中存在相同的分支和标记.
Max*_*sen 45
假设您的"上游"遥控器被命名为"origin",并且您的用户名下有自定义分叉(即"maxandersen")
当您的克隆运行以下一行(刷新跟踪所有远程git分支作为本地分支:
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
Run Code Online (Sandbox Code Playgroud)
这将为名为"origin"的远程中找到的所有分支设置跟踪分支.如果您已经使用此分支机构进行结账,除非确保跟踪到位,否则不会更改任何内容.
(可选)现在确保所有分支都是uptodate(如果已经签出分支,则非常有用):
git pull --rebase --all
Run Code Online (Sandbox Code Playgroud)
现在,所有分支都设置为跟踪和uptodate推送分支和标签到您的遥控器(用您的远程名称替换'maxandersen'):
git push --all maxandersen
git push --tags maxandersen
Run Code Online (Sandbox Code Playgroud)
在此之后你的分叉是同步的.
以下脚本执行所有这些操作,包括要求确认:
## 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
Run Code Online (Sandbox Code Playgroud)
将其保存为"updateallbranchestags.sh"并执行以下操作:
sh updateallbranches.sh origin maxandersen
Run Code Online (Sandbox Code Playgroud)
来自'origin'的所有分支/标签都将在远程命名的'maxandersen'中提供
Von*_*onC 18
你仍然需要一个本地克隆,它将:
originupstream
git push --all origin (起源是你的叉子):假设:
| 归档时间: |
|
| 查看次数: |
19044 次 |
| 最近记录: |