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

标签 git

这是场景。

我在分支 my_new_branch 中有一系列提交

我想将这个分支以不同的名称推送到远程仓库并跟踪它。

如果我这样做:

git push origin my_new_branch:different_name

它很好地 push 了分支。

但是如果我留在 my_new_branch 中并进行另一次提交,如果我只是这样做

git push

它说'一切都是最新的'

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

我当然可以

git push origin my_new_branch:different_name 

再次强调,但我如何才能跟踪它?

如果我这样做

git checkout -b my_new_branch origin/different_name

它提示分支名称已经存在。

谢谢!

最佳答案

正如您提到的,问题“How do you make an existing git branch track a remote branch?”表示可以为本地分支(自 Git1.7.0 起)设置上游分支(您推送到的分支)。

git branch --set-upstream my_new_branch origin/different_name

取代:

git config branch.my_new_branch.remote origin
git config branch.my_new_branch.merge refs/heads/different_name

默认情况下,git push 使用特殊的 refspec ':'

The special refspec : (or +: to allow non-fast-forward updates) directs git to push "matching" branches:
for every branch that exists on the local side, the remote side is updated if a branch of the same name already exists on the remote side.
This is the default operation mode if no explicit refspec is found (that is neither on the command line nor in any Push line of the corresponding remotes file).

因此你对“git push”(无参数)的麻烦。

关于Git - 如何跟踪您从本地分支创建的远程分支?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4121160/

相关文章:

git - 从 Git 存储库中的历史记录中删除空的 merge 提交

Git 基本工作流程

linux - 从 Bash 脚本中使用 Apache 执行 'git pull'

eclipse - 无法使用 https 和 SSH 链接在 Eclipse 中克隆 git 存储库

svn - 如何保持某个 git 存储库状态始终可访问?

git - 如何对 git 子模块使用相同的协议(protocol)?

c++ - git存储库中的多个引用

git - git全局配置文件中的.stCommitMsg是什么?

git - 致命的 : Unable to find remote helper for 'https'

推送到github后Android项目jar文件丢失