Git推送:为分支设置目标 [英] Git push: set target for branch

查看:134
本文介绍了Git推送:为分支设置目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想推送我当前的分支(hp1)与

  git push 



而不是

  git push origin hp1:team / hp1 

远程分支已存在。



我的本​​地分行:

  develop 
master
* hp1

git remote show origin告诉我:

 远程分支机构:
开发跟踪
跟踪的主人
团队/ h2跟踪
团队/ hp1跟踪
团队/ n1跟踪
当地分支机构配置为'git pull':
开发与远程开发合并
主合并远程主
hp1与远程团队合并/ hp1
为'git push'配置的本地参考:
主人推动主人(最新)

我已经尝试过了

  git branch --set-upstream hp1 origin / team / hp1 

  git branch --set-upstream hp1 refs / remotes / origin / team / hp1 

但都行不通。



我的同事有一个称为远程分支(team / hp1)的本地分支,上面的代码适用于他。他在最后得到一个额外的

pre $ 为'git push'配置的本地参考:
开发推动开发(向上到目前为止)
主人推动主人(最新)
团队/ hp1推到团队/ hp1(最新)

因此,也许你可以告诉我什么是错的,以及如何解决它。


$ b

编辑
my config:

  [core] 
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remoteorigin]
fetch = + refs / heads / *:refs / remotes / origin / *
url = *** @ ***:***。git
[branchmaster]
remote = origin
merge = refs / heads / master
[branchhp1]
remote = origin
merge = refs / heads / team / hp1


解决方案

首先,在第一次推送时,请执行以下操作:

  git push -u origin hp1 :团队/ hp1 

关于-u选项:


-u

--set-upstream



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

请注意,这本身并不能确定下次执行 git push 时会发生什么。当你在这个分支中执行 git pull 时,它会从你设置的上游获取它。但是当你推送时,它会推送到一个匹配的分支(在这种情况下hp1而不是team / hp1)

为了达到这个目的,你必须设置 push.default 配置值为上游。一旦你设置了它,当你从一个分支进行推送时(只要执行 git push ),它就会按照分支的提示推送到上游。<名称> .merge



所以:

  git config push.default上游

关于push.default:


push.default



定义git push在未给出$ b $的refspec时应执行的操作b命令行中,在远程中没有配置refspec,并且命令行中给出的任何选项都没有暗示refspec
。可能的
值是:

没有 - 不要推动任何东西。

匹配 - 推送所有匹配的分支。所有在两端都具有相同
名称的分支被认为是匹配的。这是默认设置。


上游 - 将当前分支推送至其上游分支。

跟踪 - 不赞成使用上游的同义词。



当前 - 将当前分支推送到同名分支。



I'd like to push my current branch (hp1) with

git push

and not

git push origin hp1:team/hp1

The remote branch already exists.

My local branches:

develop
master
* hp1

git remote show origin tells me:

Remote branches:
  develop  tracked
  master   tracked
  team/h2  tracked
  team/hp1 tracked
  team/n1  tracked
Local branches configured for 'git pull':
  develop  merges with remote develop
  master   merges with remote master
  hp1 merges with remote team/hp1
Local refs configured for 'git push':
  master   pushes to master   (up to date)

I already tried

git branch --set-upstream hp1 origin/team/hp1

and

git branch --set-upstream hp1 refs/remotes/origin/team/hp1

but both don't work.

My colleague has a local branch called as the remote branch (team/hp1) and the code above works for him. He gets at the end an additional

Local refs configured for 'git push':
  develop  pushes to develop  (up to date)
  master   pushes to master   (up to date)
  team/hp1 pushes to team/hp1 (up to date)

So maybe you can tell me what's wrong and how to fix it.

EDIT my config:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = ***@***:***.git
[branch "master"]
    remote = origin
    merge = refs/heads/master
[branch "hp1"]
    remote = origin
    merge = refs/heads/team/hp1

解决方案

First of all, when pushing for the first time, do:

git push -u origin hp1:team/hp1

About -u option:

-u
--set-upstream

For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull(1) and other commands. For more information, see branch..merge in git-config(1).

Note from the manual that, this in itself will not determine what happens when you do git push the next time. When you do git pull while in this branch, it will fetch it from the upstream that you have set. But when you push, it will push to a matching branch ( in this case hp1 and not team/hp1)

For that to work, you have to set push.default config value to upstream. Once you set that, when you push from a branch ( just do git push), it will push to the upstream as mentioned by branch.<name>.merge

So do:

git config push.default upstream

About push.default:

push.default

Defines the action git push should take if no refspec is given on the command line, no refspec is configured in the remote, and no refspec is implied by any of the options given on the command line. Possible values are:

nothing - do not push anything.

matching - push all matching branches. All branches having the same name in both ends are considered to be matching. This is the default.

upstream - push the current branch to its upstream branch.

tracking - deprecated synonym for upstream.

current - push the current branch to a branch of the same name.

这篇关于Git推送:为分支设置目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆