git將本地已經(jīng)存在的分支和一個(gè)指定的遠(yuǎn)端分支建立映射關(guān)系

Make an existing Git branch track a remote branch?

Given a branch foo and a remote upstream:

As of Git 1.8.0:

git branch -u upstream/foo

Or, if local branch foo is not the current branch:

git branch -u upstream/foo foo

Or, if you like to type longer commands, these are equivalent to the above two:

git branch --set-upstream-to=upstream/foo

git branch --set-upstream-to=upstream/foo foo

As of Git 1.7.0:

git branch --set-upstream foo upstream/foo

Notes:

All of the above commands will cause local branch foo to track remote branch foo from remote upstream. The old (1.7.x) syntax is deprecated in favor of the new (1.8+) syntax. The new syntax is intended to be more intuitive and easier to remember.Make an existing Git branch track a remote branch?

Given a branch foo and a remote upstream:

As of Git 1.8.0:

git branch -u upstream/foo

Or, if local branch foo is not the current branch:

git branch -u upstream/foo foo

Or, if you like to type longer commands, these are equivalent to the above two:

git branch --set-upstream-to=upstream/foo

git branch --set-upstream-to=upstream/foo foo

As of Git 1.7.0:

git branch --set-upstream foo upstream/foo

Notes:

All of the above commands will cause local branch foo to track remote branch foo from remote upstream. The old (1.7.x) syntax is deprecated in favor of the new (1.8+) syntax. The new syntax is intended to be more intuitive and easier to remember.

官方文檔:git-branch(1) Manual Page

-u <upstream>

--set-upstream-to=<upstream>

Set up <branchname>'s tracking information

so <upstream> is considered <branchname>'s upstream branch.

If no <branchname> is specified, then it defaults to the current branch.

假定澡为,需要把foo分支涂身,和遠(yuǎn)端的foo分支進(jìn)行映射识颊,遠(yuǎn)端名稱為upstream

如果當(dāng)foo分支不是當(dāng)前分支,使用如下命令

git branch -u upstream/foo foo

如果foo分支是當(dāng)前分支

git branch -u upstream/foo

==============================================================================

在checkout分支的時(shí)候件炉,就進(jìn)行映射

he ProGit book has a very good explanation:

Tracking Branches

Checking out a local branch from a remote branch automatically creates what is called a tracking branch. Tracking branches are local branches that have a direct relationship to a remote branch. If you’re on a tracking branch and type git push, Git automatically knows which server and branch to push to. Also, running git pull while on one of these branches fetches all the remote references and then automatically merges in the corresponding remote branch.

When you clone a repository, it generally automatically creates a master branch that tracks origin/master. That’s why git push and git pull work out of the box with no other arguments. However, you can set up other tracking branches if you wish — ones that don’t track branches on origin and don’t track the master branch. The simple case is the example you just saw, running git checkout -b [branch] [remotename]/[branch]. If you have Git version 1.6.2 or later, you can also use the --track shorthand:

$ git checkout --track origin/serverfix
Branch serverfix set up to track remote branch refs/remotes/origin/serverfix.
Switched to a new branch "serverfix"

To set up a local branch with a different name than the remote branch, you can easily use the first version with a different local branch name:

$ git checkout -b sf origin/serverfix
Branch sf set up to track remote branch refs/remotes/origin/serverfix.
Switched to a new branch "sf"

Now, your local branch sf will automatically push to and pull from origin/serverfix.

查看本地分支和遠(yuǎn)端分支的映射情況git branch -vv

查看映射

Administrator@LuJunTao MINGW64 /d/SourceCode/GameSourceCode/Hearthstone-Deck-Tracker (chucklu_zhCN)
$ git branch -vv
chucklu_master 8739b35 [chucklu/master] v0.10.16 (mainwindow topmost fix)

  • chucklu_zhCN d5dbcc8 1.修改默認(rèn)語(yǔ)言為中文zhCN
    master 8739b35 [epix37/master] v0.10.16 (mainwindow topmost fix)
    ui-translation cade481 [epix37/ui-translation] a few more resx entries

發(fā)現(xiàn)chucklu_zhCN分支沒有和遠(yuǎn)端建立映射關(guān)系

添加映射

Administrator@LuJunTao MINGW64 /d/SourceCode/GameSourceCode/Hearthstone-Deck-Tracker (chucklu_zhCN)
$ git branch -u chucklu/chucklu_zhCN
Branch chucklu_zhCN set up to track remote branch chucklu_zhCN from chucklu.

再次查看映射

Administrator@LuJunTao MINGW64 /d/SourceCode/GameSourceCode/Hearthstone-Deck-Tracker (chucklu_zhCN)
$ git branch -vv
chucklu_master 8739b35 [chucklu/master] v0.10.16 (mainwindow topmost fix)

  • chucklu_zhCN d5dbcc8 [chucklu/chucklu_zhCN: ahead 1] 1.修改默認(rèn)語(yǔ)言為中文zhCN //可以發(fā)現(xiàn)這個(gè)已經(jīng)映射成功了
    master 8739b35 [epix37/master] v0.10.16 (mainwindow topmost fix)
    ui-translation cade481 [epix37/ui-translation] a few more resx entries官方文檔:git-branch(1) Manual Page

-u <upstream>

--set-upstream-to=<upstream>

Set up <branchname>'s tracking information

so <upstream> is considered <branchname>'s upstream branch.

If no <branchname> is specified, then it defaults to the current branch.

假定,需要把foo分支诞挨,和遠(yuǎn)端的foo分支進(jìn)行映射碍粥,遠(yuǎn)端名稱為upstream

如果當(dāng)foo分支不是當(dāng)前分支,使用如下命令

git branch -u upstream/foo foo

如果foo分支是當(dāng)前分支

git branch -u upstream/foo

==============================================================================

在checkout分支的時(shí)候,就進(jìn)行映射

he ProGit book has a very good explanation:

Tracking Branches

Checking out a local branch from a remote branch automatically creates what is called a tracking branch. Tracking branches are local branches that have a direct relationship to a remote branch. If you’re on a tracking branch and type git push, Git automatically knows which server and branch to push to. Also, running git pull while on one of these branches fetches all the remote references and then automatically merges in the corresponding remote branch.

When you clone a repository, it generally automatically creates a master branch that tracks origin/master. That’s why git push and git pull work out of the box with no other arguments. However, you can set up other tracking branches if you wish — ones that don’t track branches on origin and don’t track the master branch. The simple case is the example you just saw, running git checkout -b [branch] [remotename]/[branch]. If you have Git version 1.6.2 or later, you can also use the --track shorthand:

$ git checkout --track origin/serverfix
Branch serverfix set up to track remote branch refs/remotes/origin/serverfix.
Switched to a new branch "serverfix"

To set up a local branch with a different name than the remote branch, you can easily use the first version with a different local branch name:

$ git checkout -b sf origin/serverfix
Branch sf set up to track remote branch refs/remotes/origin/serverfix.
Switched to a new branch "sf"

Now, your local branch sf will automatically push to and pull from origin/serverfix.

查看本地分支和遠(yuǎn)端分支的映射情況git branch -vv

查看映射

Administrator@LuJunTao MINGW64 /d/SourceCode/GameSourceCode/Hearthstone-Deck-Tracker (chucklu_zhCN)
$ git branch -vv
chucklu_master 8739b35 [chucklu/master] v0.10.16 (mainwindow topmost fix)

  • chucklu_zhCN d5dbcc8 1.修改默認(rèn)語(yǔ)言為中文zhCN
    master 8739b35 [epix37/master] v0.10.16 (mainwindow topmost fix)
    ui-translation cade481 [epix37/ui-translation] a few more resx entries

發(fā)現(xiàn)chucklu_zhCN分支沒有和遠(yuǎn)端建立映射關(guān)系

添加映射

Administrator@LuJunTao MINGW64 /d/SourceCode/GameSourceCode/Hearthstone-Deck-Tracker (chucklu_zhCN)
$ git branch -u chucklu/chucklu_zhCN
Branch chucklu_zhCN set up to track remote branch chucklu_zhCN from chucklu.

再次查看映射

Administrator@LuJunTao MINGW64 /d/SourceCode/GameSourceCode/Hearthstone-Deck-Tracker (chucklu_zhCN)
$ git branch -vv
chucklu_master 8739b35 [chucklu/master] v0.10.16 (mainwindow topmost fix)

  • chucklu_zhCN d5dbcc8 [chucklu/chucklu_zhCN: ahead 1] 1.修改默認(rèn)語(yǔ)言為中文zhCN //可以發(fā)現(xiàn)這個(gè)已經(jīng)映射成功了
    master 8739b35 [epix37/master] v0.10.16 (mainwindow topmost fix)
    ui-translation cade481 [epix37/ui-translation] a few more resx entries

https://www.cnblogs.com/chucklu/p/4730745.html

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末祭衩,一起剝皮案震驚了整個(gè)濱河市灶体,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌汪厨,老刑警劉巖赃春,帶你破解...
    沈念sama閱讀 206,482評(píng)論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異劫乱,居然都是意外死亡织中,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,377評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門衷戈,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)狭吼,“玉大人,你說(shuō)我怎么就攤上這事殖妇〉篌希” “怎么了?”我有些...
    開封第一講書人閱讀 152,762評(píng)論 0 342
  • 文/不壞的土叔 我叫張陵谦趣,是天一觀的道長(zhǎng)疲吸。 經(jīng)常有香客問我,道長(zhǎng)前鹅,這世上最難降的妖魔是什么摘悴? 我笑而不...
    開封第一講書人閱讀 55,273評(píng)論 1 279
  • 正文 為了忘掉前任,我火速辦了婚禮舰绘,結(jié)果婚禮上蹂喻,老公的妹妹穿的比我還像新娘。我一直安慰自己捂寿,他們只是感情好口四,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,289評(píng)論 5 373
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著秦陋,像睡著了一般蔓彩。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上驳概,一...
    開封第一講書人閱讀 49,046評(píng)論 1 285
  • 那天粪小,我揣著相機(jī)與錄音,去河邊找鬼抡句。 笑死探膊,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的待榔。 我是一名探鬼主播逞壁,決...
    沈念sama閱讀 38,351評(píng)論 3 400
  • 文/蒼蘭香墨 我猛地睜開眼流济,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了腌闯?” 一聲冷哼從身側(cè)響起绳瘟,我...
    開封第一講書人閱讀 36,988評(píng)論 0 259
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎姿骏,沒想到半個(gè)月后糖声,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 43,476評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡分瘦,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,948評(píng)論 2 324
  • 正文 我和宋清朗相戀三年蘸泻,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片嘲玫。...
    茶點(diǎn)故事閱讀 38,064評(píng)論 1 333
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡悦施,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出去团,到底是詐尸還是另有隱情抡诞,我是刑警寧澤,帶...
    沈念sama閱讀 33,712評(píng)論 4 323
  • 正文 年R本政府宣布土陪,位于F島的核電站昼汗,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏鬼雀。R本人自食惡果不足惜顷窒,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,261評(píng)論 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望取刃。 院中可真熱鬧,春花似錦出刷、人聲如沸璧疗。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,264評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)崩侠。三九已至,卻和暖如春坷檩,著一層夾襖步出監(jiān)牢的瞬間却音,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,486評(píng)論 1 262
  • 我被黑心中介騙來(lái)泰國(guó)打工矢炼, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留系瓢,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 45,511評(píng)論 2 354
  • 正文 我出身青樓句灌,卻偏偏與公主長(zhǎng)得像夷陋,于是被迫代替她去往敵國(guó)和親欠拾。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,802評(píng)論 2 345

推薦閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,294評(píng)論 0 10
  • origin websiteComparing WorkflowsCentralized Workflow Fea...
    伍帆閱讀 504評(píng)論 0 0
  • 1. GIT命令 git init在本地新建一個(gè)repo骗绕,進(jìn)入一個(gè)項(xiàng)目目錄藐窄,執(zhí)行g(shù)it init,會(huì)初始化一個(gè)re...
    江邊一蓑煙閱讀 785評(píng)論 0 0
  • 因?yàn)樵奶L(zhǎng)超出字?jǐn)?shù)酬土,Lesson 3 就放在另一篇文章里 How to Use Git and GitHub 標(biāo)...
    赤樂君閱讀 5,175評(píng)論 1 5
  • Lesson 3: Using GitHub to Collaborate 3.1 Creating a GitH...
    赤樂君閱讀 6,038評(píng)論 3 11