簡體   English   中英

如何告訴Git總是拉主分支?

[英]How to tell Git to always pull the master branch?

我發現git docs在這個問題上非常神秘。 我想做一件簡單的事情,但似乎這樣做並不簡單。

我有以下情況:

$ git remote -v
origin  git://192.168.0.49/mnt/repos
stick   /mnt/titanium/podaci/repos

我可以使用git pull從原點獲取和合並,這樣可以正常工作:

$ git pull
Already up-to-date.

我可以像這樣從棍子里拉出來:

$ git pull stick master
Already up-to-date.

但是,當我從沒有主要部分的棍子拉出來時,我得到這樣的信息:

$ git pull stick
From /mnt/titanium/podaci/repos
 * [new branch]      su2009  -> stick/su2009
You asked me to pull without telling me which branch you
want to merge with, and 'branch.master.merge' in
your configuration file does not tell me either.  Please
name which branch you want to merge on the command line and
try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details on the refspec.

If you often merge with the same branch, you may want to
configure the following variables in your configuration
file:

    branch.master.remote = <nickname>
    branch.master.merge = <remote-ref>
    remote.<nickname>.url = <url>
    remote.<nickname>.fetch = <refspec>

See git-config(1) for details.

有些事讓我困惑。 您的配置文件 ”在這里意味着什么? 我應該編輯哪個文件,以及我應該輸入什么? 這個案子的昵稱是什么?

我希望我想要完成的事情非常普遍,但我無法通過一個例子找到一個直截了當的答案。

“您的配置文件”在這里意味着什么?

您的repo的配置文件,位於您的repo根目錄下的.git/config ~/.gitconfig上還有一個每用戶全局配置文件,但你不想在那里放置特定於repo的設置。)

我應該編輯哪個文件,以及我應該輸入什么?

您可以使用git config程序來編寫配置信息,而不是手動輸入。 但是,如果你想手動完成,只需打開.git/config - 語法相當簡單。

這個案子的昵稱是什么?

在這種情況下,昵稱是遙控器的名稱 - 所以“棒”。 您不必擔心remote.*選項,因為已經設置了這些選項,但您確實需要設置branch.*選項。 這些選項告訴Git在使用stick進行git pull時要合並什么。

假設從棒上做git pull時你想從棒中合並大師。 你可以這樣做:

# Sets stick as default remote for git pull.
# Note that origin will no longer be the default remote for git pull!
$ git config branch.master.remote stick

# Automatically merge in stick's master branch when doing a git pull
$ git config branch.master.merge refs/heads/master

所以現在,當你在沒有任何遠程或refspec信息的情況下執行git pull ,它將從stick獲取所有分支,並在stick的master分支中合並。 請注意,原點不再是默認的遙控器; 要合並origin的master分支,你必須使用git pull origin master

如果你不想更改默認的遙控器,你將不得不繼續使用git pull stick master

暫無
暫無

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

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