Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git-如何跟踪从本地分支创建的远程分支?_Git - Fatal编程技术网

Git-如何跟踪从本地分支创建的远程分支?

Git-如何跟踪从本地分支创建的远程分支?,git,Git,下面是一个场景 我在我的新分支中有一系列提交 我想把这个分支作为一个不同的名称推到远程回购并跟踪它 如果我这样做: git push origin my_new_branch:different_name 它把树枝往上推得很好 但如果我留在我的新分支机构,再做一次承诺,如果我这么做的话 git push 上面写着“一切都是最新的” 此外,如果我查看.git/config,我可以看到它没有设置跟踪分支 我当然可以 git push origin my_new_branch:different_

下面是一个场景

我在我的新分支中有一系列提交

我想把这个分支作为一个不同的名称推到远程回购并跟踪它

如果我这样做:

git push origin my_new_branch:different_name
它把树枝往上推得很好

但如果我留在我的新分支机构,再做一次承诺,如果我这么做的话

git push
上面写着“一切都是最新的”

此外,如果我查看.git/config,我可以看到它没有设置跟踪分支

我当然可以

git push origin my_new_branch:different_name 
再说一次,但我如何让它跟踪

如果我这样做

git checkout -b my_new_branch origin/different_name
它抱怨分支名称已经存在


谢谢

正如您所提到的,问题“”表示可以为本地分支(自Git1.7.0以来)设置上游分支(推送到的位置)

它取代了:

git config branch.my_new_branch.remote origin
git config branch.my_new_branch.merge refs/heads/different_name
默认情况下,
gitpush
使用特殊的refspec'
'

特殊的refspec
(或允许非快进更新的
+:
)指示git推送“匹配”分支
对于本地端存在的每个分支,如果远程端已经存在同名分支,则会更新远程端。
如果找不到明确的refspec(既不在命令行中,也不在相应远程文件的任何推送行中),则这是默认操作模式


因此,您在“
git push
”(无参数)时会遇到麻烦。

如果您在推送时记得使用-u,git会自动为您设置此选项

-u、 --逆流而上

对于每个最新或成功推送的分支,添加上游(跟踪)引用,由无参数git pull(1)和其他命令使用。有关更多信息,请参阅git配置中的branch..merge(1)


实际上看起来与下面的问题相同,如果我想将我的_new_分支分为两个独立的远程分支名称remote_branchA和remote_branchB,是否使用了此命令
git-push-origin-my\u-new\u分支:remote\u-branchA
git-push-origin-my\u-new\u分支:remote\u-branchB
@Kit:您的命令应该可以工作;当推送到多个分支时,您不能再依赖分支的配置,您需要指定远程repo和目标refspec,您可以这样做。
git config branch.my_new_branch.remote origin
git config branch.my_new_branch.merge refs/heads/different_name