簡體   English   中英

Git push:為分支設置目標

[英]Git push: set target for branch

我想用我的當前分支(hp1)

git push

並不是

git push origin hp1:team/hp1

遠程分支已經存在。

我當地的分店:

develop
master
* hp1

git遠程顯示來源告訴我:

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)

我已經試過了

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

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

但兩者都不起作用。

我的同事有一個叫做遠程分支的本地分支(team / hp1),上面的代碼適合他。 他最后得到了一個額外的

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)

所以也許你可以告訴我什么是錯的以及如何解決它。

編輯我的配置:

[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

首先,在第一次推送時,請執行以下操作:

git push -u origin hp1:team/hp1

關於-u選項:

-u
--set上游

對於每個最新或成功推送的分支,添加上游(跟蹤)引用,由無參數git-pull(1)和其他命令使用。 有關更多信息,請參閱git-config(1)中的branch..merge。

從手冊中注意到,這本身並不能確定下次進行git push時會發生什么。 當您在此分支中執行git pull時,它將從您設置的上游獲取它。 但是當你推動時,它將推送到匹配的分支(在這種情況下是hp1而不是team / hp1)

為此,您必須將push.default配置值設置為upstream 一旦你設置了它,當你從一個分支推送(只需要執行git push )時,它將推送到branch.<name>.merge所提到的上游branch.<name>.merge

所以:

git config push.default upstream

關於push.default:

push.default

如果在命令行上沒有給出refspec,在遠程中沒有配置refspec,並且命令行上給出的任何選項都沒有暗示refspec,則定義git push應采取的操作。 可能的值是:

沒有 - 不要推動任何東西。

匹配 - 推送所有匹配的分支。 兩端具有相同名稱的所有分支都被認為是匹配的。 這是默認值。

上游 - 將當前分支推送到其上游分支。

跟蹤 - 已棄用的上游同義詞。

current - 將當前分支推送到同名分支。

(2012年3月): 注意:“上游”政策很快就會成為默認政策
(git1.7.10之后的某個時間)

請參閱“ 請討論:什么”git push“應該做什么,當你不說什么推?

在當前設置 (即push.default=matching )中, 不帶參數的git push將推送本地和遠程同名的所有分支
這通常適用於開發人員推送到自己的公共存儲庫時,但在使用共享存儲庫時可能會造成混淆。

建議是將默認值更改為“ upstream ,即僅推送當前分支,並將其推送到分支git pull將從中拉出。
另一位候選人是“ current ”; 這會將當前分支僅推送到同名的遠程分支。

到目前為止所討論的內容可以在這個帖子中看到:

http://thread.gmane.org/gmane.comp.version-control.git/192547/focus=192694

以前的相關討論包括:

要加入討論,請將您的消息發送至:git@vger.kernel.org

使用-u選項git push

$ git push -u origin hp1:team/hp1

然后,在那之后,您可以:

$ git push

以下將允許不必為第一個git push指定-u ${branch_name}

git config "branch.${branch_name}.remote" origin
git config "branch.${branch_name}.merge" "refs/heads/${branch_name}"

當然,它更多的是打字,但不是在設置一個工作區的腳本中。 它也不會過早地將分支推送到遠程倉庫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM