/
7_branches_arent_just_for_birds.html
94 lines (72 loc) · 5.66 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
90
91
92
93
94
<div id="challenge-desc" class="chal-goal blue-border border-box">
<p>Add a branch to your forked repository to work on your changes.</p>
</div>
<div class="chal-background light-blue solid-box">
<h2>Branches</h2>
<p>Git repositories use branches to isolate work when needed. It's common practice when working on a project or with others on a project to create a <strong>branch</strong> to keep your working changes in. This way you can do your work while the main, commonly named 'master', branch stays stable. When the work on your branch is finished you merge it back into the 'master' master branch.</p>
<p>The diagram below shows how you can branch off of your 'master' branch, do work and the merge those changes back into 'master'. You can even branch off of a branch if you need to, the 'master' branch doesn't have to be the base.</p>
<img src="../assets/imgs/branches.png" width="100%">
<p>For a great visualization on how branches work in a project, see this GitHub Guide: <a href="http://guides.github.com/overviews/flow/" target="_blank">guides.github.com/overviews/flow</a></p>
<h2>GitHub Pages</h2>
<p>GitHub will automatically serve and host static website files in branches named 'gh-pages'. This free service i called <a href="http://pages.github.com">GitHub Pages</a>. Since the project you forked creates a website, its main branch is named 'gh-pages' instead of 'master'. All repositories that have a 'gh-pages' branch with website files can be found, in their hosted version, using this pattern for the URL:</p>
<code>http://githubusername.github.io/repositoryname</code>
</div>
<div class="chal-step blue-border border-box">
<h3>Create a branch</h3>
<p>When you create a branch, Git copies everything from the current branch you're on and places it in the branch you've requested be made.</p>
<p>While still inside of your local 'patchwork' repository, type <code>git status</code> to see what branch you're currently on. Git should reply that you're on the 'gh-pages' branch.</p>
<p>Now create a new branch and name it "add-<username>", where 'username' is
your username. For instance, "add-jlord". <strong>Branches are case-sensitive so name your branch exactly the way your GitHub name appears</strong>.</p>
<p><code class="shell">git branch <BRANCHNAME></code></p>
<p>Now you have a branch with a new name that is identical to 'gh-pages'.</p>
<p>To go into that branch and work on it, similar to using <code>cd</code> to
change directory in terminal, you <strong>checkout</strong> a branch. To go on your new branch:</p>
<p><code class="shell">git checkout <BRANCHNAME></code></p>
</div>
<div class="chal-step blue-border border-box">
<h3>Step: Create a new file</h3>
<p>Back in your text editor:</p>
<ul>
<li>Create a new file named <span style="white-space: nowrap;">"add-<USERNAME>.txt"</span>, where 'username' is your username. For instance, "add-jlord.txt".</li>
<li>Then, just write your GitHub username in it, that's it and that's all. For instance, I'd type 'jlord'.</li>
<li>Save this file in the 'contributors' folder in Patchwork <strong>Patchwork/contributors/add-yourusername.txt</strong></li>
<li>Next, check in your changes (see below).</li>
</ul>
</div>
<div class="chal-step blue-border border-box">
<h3>Check-in</h3>
<p>Go through the steps for checking in a project: </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>Now push your update to your fork on GitHub:</p>
<p><code class="shell">git push origin <BRANCHNAME></code></p>
<p>Make sure that you're pushing to 'origin', which is your fork's address on GitHub. If you get an error check to make sure you have your remotes set up correctly with 'origin' pointing to your fork and 'upstream' pointing to the original repository: <code>git remote -v</code>
</div>
{{{ verify_directory_button }}}
<div class="chal-no-pass grey-border border-box">
<h4>File NOT in contributors folder</h4>
<p>The file you create should inside the existing 'contributors' folder in the Patchwork repository. If you put it somewhere else, simply use Finder or Windows Explorer to move your file into the folder. You can check <code>git status</code> again and you'll find it sees your changes. Stage and then commit "all" (-A) of these changes (additions and deletions) with the commands below.</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>Branch name expected: _____</h4>
<p>The branch name should match your user name exactly. To change your branch name:</p>
<p><code class="shell">git branch -m <NEWBRANCHNAME></code></p>
<p>When you've made your updates, verify again!</p>
</div>
<div class="chal-tip grey-border border-box">
<ul class="no-list-style">
<li><strong>You can create and switch to a branch in one line</strong></li>
<li><code class="shell">git checkout -b <BRANCHNAME></code></li>
<li><strong>Create a new branch</strong></li>
<li><code class="shell">git branch <BRANCHNAME></code></li>
<li><strong>Move onto a branch</strong></li>
<li><code class="shell">git checkout <BRANCHNAME></code></li>
<li><strong>List the branches</strong></li>
<li><code class="shell">git branch</code></li>
<li><strong>Rename a branch you're currently on</strong></li>
<li><code class="shell">git branch -m <NEWBRANCHNAME></code></li>
<li><strong>Verify what branch you're working on</strong></li>
<li><code class="shell">git status</code></li>
</ul>
</div>