/
7_branches_arent_just_for_birds.html
89 lines (66 loc) · 5.39 KB
/
7_branches_arent_just_for_birds.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<div class="challenge">
<h2>關卡內容:</h2>
<p>在你的 <n>fork</n> 新增 <n>branch</n>。</p>
</div>
<h2><n>Branches</n></h2>
<p>Git <n>repositories</n> 用 <n>branches</n> 來隔離進度。當需要跟其他人一起進行專案時,在你完成負責的部份之前,經常需要利用 <strong><n>branch</n></strong> 來保護你對程式所做的修改。如此,你就可以讓主要的 'master' <n>branch</n> 保持穩定,不被未完成的修改影響。等到你完成在 <n>branch</n> 上的修改,就可以把它 <v>merge</v> 回 'master' <n>branch</n>。</p>
<img src="../assets/imgs/branches.png" width="600">
<p>在 GitHub Guide 中我們有提供解釋 <n>branches</n> 運作方式的示意圖:<a href="https://guides.github.com/overviews/flow/" target="_blank">guides.github.com/overviews/flow</a></p>
<h2>GitHub Pages</h2>
<p>GitHub 會自動發佈你放在 'gh-pages' <n>branch</n> 裡的靜態檔案,並架設一個網站。由於你 <v>forked</v> 的專案內容是一個網站,所以它的預設 <n>branch</n> 是 'gh-pages' 而不是 'master'。而你會發現這些網站,網址都長得像這樣:</p>
<code>http://githubusername.github.io/repositoryname</code>
<h2>步驟:新增 <n>branch</n></h2>
<p>當你新增 <n>branch</n> 的時候,Git 會拷貝目前 <n>branch</n> 上所有的檔案到新的 <n>branch</n>。</p>
<p>在終端機輸入 <code>git status</code> 可以知道目前你在哪個 <n>branch</n>(應該會在 'gh-pages')。</p>
<p>新增一個 <n>branch</n> 並命名為「add-<username>」,請用你的帳號名稱替換掉 'username'。例如「add-jlord」。<strong><n>Branches</n> 的名字有分大小寫,所以請確定輸入的帳號名稱跟 GitHub 上顯示的一模一樣。</strong></p>
<p><code class="shell">git branch <BRANCHNAME></code></p>
<p>水啦!你擁有了一個全新、內容跟 'gh-pages' 一模一樣的 <n>branch</n>!</p>
<p>就像終端機去另一個資料夾的指令 <code>cd</code> 一樣,請 <strong><v>checkout</v></strong>
到剛才新增的 <n>branch</n>:</p>
<p><code class="shell">git checkout <BRANCHNAME></code></p>
<h2>步驟:新增檔案</h2>
<p>接下來我們回到文字編輯器:</p>
<ul>
<li>新增一個檔案並命名為 <span style="white-space: nowrap;">「add-<USERNAME>.txt」</span>,請用你的帳號名稱替換 'username',像這樣,「add-jlord.txt」。</li>
<li>在檔案裡寫下你的 GitHub 帳號名稱。例如,我就會寫 'jlord'。</li>
<li>將檔案存到在 Patchwork 裡的 'contributors' 資料夾: <strong>Patchwork/contributors/add-yourusername.txt</strong></li>
<li>接著,把你的修改記錄下來!</li>
</ul>
<h2>步驟:紀錄</h2>
<p>按照以下的步驟,把剛才的修改用 Git 記錄下來:</p>
<p><code class="shell">git status</code></p>
<p><code class="shell">git add <FILENAME></code></p>
<p><code class="shell">git commit -m "<commit message>"</code></p>
<p><v>Push</v> 剛才記錄好的修改到 GitHub 上,你 <adj>forked</adj> 的 <n>repository</n> 裡頭:</p>
<p><code class="shell">git push origin <BRANCHNAME></code></p>
{{{verify_directory_button}}}
<div class="didnt-pass">
<h2><code>git-it verify</code> 的時候沒有通過?</h2>
<h4>File NOT in contributors folder</h4>
<p>剛才新增的檔案應該要放到 Patchwork <n>repository</n> 的 'contributors'
資料夾裡。如果不小心放到別的地方,請打開 Finder 或是 Windows 的檔案總管將該檔案移到
'contributors' 資料夾,然後可以用 <code>git status</code> 看你剛才移動檔案之後所造成的結果。用以下的指令 <v>Stage</v> 並且 <v>commit</v> 全部的修改(加上 -A,會將新增檔案跟刪除檔案的動作一起記錄下來):</p>
<p><code class="shell">git add -A</code></p>
<p><code class="shell">git commit -m "move file into contributors folder"</code></p>
<h4><n>Branch</n> name expected: _____</h4>
<p><n>Branch</n> 的名字應該要跟你的帳號名稱一模一樣。用以下的指令修改 <n>branch</n> 的名字:</p>
<p><code class="shell">git branch -m <NEWBRANCHNAME></code></p>
<p>完成以上的動作之後,再執行一次 <code>git-it verify</code>!</p>
</div>
<div class="blue-border-box">
<h2>撇步</h2>
<ul>
<li>只用一個指令就新增並切換到新的 <n>branch</n></li>
<li><code class="shell">git checkout -b <BRANCHNAME></code></li>
<li>新增 <n>branch</n></li>
<li><code class="shell">git branch <BRANCHNAME></code></li>
<li>切換到另一個 <n>branch</n></li>
<li><code class="shell">git checkout <BRANCHNAME></code></li>
<li>列出所有的 <n>branches</n></li>
<li><code class="shell">git branch</code></li>
<li>重新命名目前所在的 <n>branch</n></li>
<li><code class="shell">git branch -m <NEWBRANCHNAME></code></li>
<li>看目前正在哪個 <n>branch</n></li>
<li><code class="shell">git status</code></li>
</ul>
</div>