6

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

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

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

命令应该是什么样子?我试过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?
4

4 回答 4

19

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

git checkout tagname && git checkout -b newbranch

或者

git checkout tagname -b newbranch
于 2013-02-23T17:45:37.123 回答
10

这对我有用

$git fetch --tags
$git tag
$git checkout -b <new_branch_name> <tagname>
于 2014-11-26T15:18:25.620 回答
4

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

git checkout -b newbranch tagname
于 2013-02-23T17:51:03.233 回答
-2

以下 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}"
于 2016-12-09T07:38:27.703 回答