来自远程标签的 Git 分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15043450/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:12:58  来源:igfitidea点击:

Git branch from remote tag

gitgit-branchgit-tag

提问by dtrunk

I've created a new local git repository mirrored from another remote repository:

我创建了一个从另一个远程存储库镜像的新本地 git 存储库:

git init
git remote add original {url}
git pull original master
git remote add origin {url}
git push -u origin master

This would create a mirror of originals master branch. Now I would like to create a new branch of a tag from original.

这将创建一个original主分支的镜像。现在我想从original.

How the commands should look like? I tried git checkout -b newbranch original/tagnamebut I got:

命令应该是什么样子的?我试过了,git checkout -b newbranch original/tagname但我得到了:

fatal: Cannot update paths and switch to branch 'newbranch' at the same time.
Did you intend to checkout 'original/tagname' which can not be resolved as commit?

回答by jchapa

You need to wrap this in two instructions

您需要将其包装在两条指令中

git checkout tagname && git checkout -b newbranch

Alternatively

或者

git checkout tagname -b newbranch

回答by nicky12345

This worked for me

这对我有用

$git fetch --tags
$git tag
$git checkout -b <new_branch_name> <tagname>

回答by Chronial

There is no concept of “remote tracking tags” like there are “remote tracking branches”. You either get the tags from the repo or you don't. At least in the standard settings. You can change that, but I would not recommend that. Does this not work?

没有“远程跟踪标签”的概念,就像有“远程跟踪分支”一样。您要么从回购中获取标签,要么不获取。至少在标准设置中。你可以改变它,但我不建议这样做。这不起作用吗?

git checkout -b newbranch tagname

回答by imesh

The following bash script can be used for automating this process:

以下 bash 脚本可用于自动化此过程:

#!/bin/bash

old_name="old-branch-name"
new_name="new-branch-name"

git checkout ${old_name}
git branch -m ${old_name} ${new_name}
git push origin :${old_name} ${new_name}
git push origin -u ${new_name}
echo "Branch ${old_name} renamed to ${new_name}"