diff --git a/rys-git-tutorial.md b/Home.md
similarity index 89%
rename from rys-git-tutorial.md
rename to Home.md
index 6c7ade1..473c202 100644
--- a/rys-git-tutorial.md
+++ b/Home.md
@@ -1,20 +1,23 @@
-
+
[]{#navigation-document.xhtml}
:::: {#navigation-document.xhtml_page}
::: {#navigation-document.xhtml_content}
+
```{=html}
```
+
:::
::::
@@ -22,6 +25,7 @@
:::: {#introduction.xhtml_page}
::: {#introduction.xhtml_content}
+
# Introduction {#introduction.xhtml_introduction}
Git is a version control system (VCS) created for a single task:
@@ -44,7 +48,7 @@ the entire project and give it a new name. Just think about how many
times you've saved a "backup" called `my-term-paper-2.doc`. This is the
simplest form of version control.
-
+
But, it's easy to see how copying files from folder to folder could
prove disastrous for software developers. What happens if you mis-label
@@ -62,9 +66,9 @@ way, you would only have a single "checked out" copy of the project at
any given time, eliminating the possibility of mixing up or losing
revisions.
-
+
-At this point, versioning only took place on the developer's *local*
+At this point, versioning only took place on the developer's _local_
computer---there was no way to efficiently share code amongst several
programmers.
@@ -77,7 +81,7 @@ them back into the project over a network. This setup let several
programmers collaborate on a project by giving them a single point of
entry.
-
+
While a big improvement on local VCS, centralized systems presented a
new set of problems: how do multiple users work on the same files at the
@@ -98,12 +102,12 @@ team.
The next generation of revision control programs shifted away from the
idea of a single centralized repository, opting instead to give every
-developer their own *local* copy of the entire project. The resulting
-*distributed* network of repositories let each developer work in
+developer their own _local_ copy of the entire project. The resulting
+_distributed_ network of repositories let each developer work in
isolation, much like a local VCS---but now the conflict resolution
problem of CVCS had a much more elegant solution.
-
+
Since there was no longer a central repository, everyone could develop
at their own pace, store the updates locally, and put off merging
@@ -129,10 +133,10 @@ of a new open-source DVCS as a replacement. This was the birth of Git.
As a source code manager for the entire Linux kernel, Git had several
unique constraints, including:
-- Reliability
-- Efficient management of large projects
-- Support for distributed development
-- Support for non-linear development
+- Reliability
+- Efficient management of large projects
+- Support for distributed development
+- Support for non-linear development
While other DVCSs did exist at the time (e.g., GNU's Arch or David
Roundy's Darcs), none of them could satisfy this combination of
@@ -155,8 +159,8 @@ real-world scenarios. But first, you'll need a working Git installation
to experiment with. Downloads for all supported platforms are available
via the [official Git website](http://git-scm.com).
-For Windows users, this will install a special command shell called *Git
-Bash*. You should be using this shell instead of the native command
+For Windows users, this will install a special command shell called _Git
+Bash_. You should be using this shell instead of the native command
prompt to run Git commands. OS X and Linux users can access Git from a
normal shell. To test your installation, open a new command prompt and
run `git --version`. It should output something like
@@ -164,7 +168,7 @@ run `git --version`. It should output something like
## Get Ready! {#introduction.xhtml_get-ready}
-Remember that *Ry's Git Tutorial* is designed to *demonstrate* Git's
+Remember that _Ry's Git Tutorial_ is designed to _demonstrate_ Git's
feature set, not just give you a superficial overview of the most common
commands. To get the most out of this tutorial, it's important to
actually execute the commands you're reading about. So, make sure you're
@@ -176,6 +180,7 @@ sitting in front of a computer, and let's get to it!
:::: {#the-basics.xhtml_page}
::: {#the-basics.xhtml_content}
+
# The Basics {#the-basics.xhtml_the-basics}
Now that you have a basic understanding of version control systems in
@@ -207,7 +212,7 @@ project. Create a new folder called `my-git-repo` to store the project,
then add a file called `index.html` to it. Open `index.html` in your
favorite text editor and add the following HTML.
-``` cp
+```cp
@@ -216,8 +221,8 @@ favorite text editor and add the following HTML.
A Colorful Website
-
This is a website about color!
-
+
This is a website about color!
+
News
Nothing going on (yet)
@@ -237,7 +242,7 @@ Now, we're ready to create our first Git repository. Open a command
prompt (or Git Bash for Windows users) and navigate to the project
directory by executing:
-``` k
+```k
cd /path/to/my-git-repo
```
@@ -245,14 +250,14 @@ where `/path/to/my-git-repo` is a path to the folder created in the
previous step. For example, if you created `my-git-repo` on your
desktop, you would execute:
-``` k
+```k
cd ~/Desktop/my-git-repo
```
Next, run the following command to turn the directory into a Git
repository.
-``` k
+```k
git init
```
@@ -270,13 +275,13 @@ Before we try to start creating revisions, it would be helpful to view
the status of our new repository. Execute the following in your command
prompt.
-``` k
+```k
git status
```
This should output something like:
-``` c
+```c
# On branch master
#
# Initial commit
@@ -297,8 +302,8 @@ doesn't automatically track files because there are often project files
that we don't want to keep under revision control. These include
binaries created by a C program, compiled Python modules (`.pyc` files),
and any other content that would unnecessarily bloat the repository. To
-keep a project small and efficient, you should only track *source* files
-and omit anything that can be *generated* from those files. This latter
+keep a project small and efficient, you should only track _source_ files
+and omit anything that can be _generated_ from those files. This latter
content is part of the build process---not revision control.
## Stage a Snapshot {#the-basics.xhtml_stage-a-snapshot}
@@ -307,7 +312,7 @@ So, we need to explicitly tell Git to add `index.html` to the
repository. The aptly named `git add` command tells Git to start
tracking `index.html`:
-``` k
+```k
git add index.html
git status
```
@@ -315,7 +320,7 @@ git status
In place of the "Untracked files" list, you should see the following
status.
-``` c
+```c
# Changes to be committed:
# (use "git rm --cached ..." to unstage)
#
@@ -333,7 +338,7 @@ Git's term for creating a snapshot is called **staging** because we can
add or remove multiple files before actually committing it to the
project history. Staging gives us the opportunity to group related
changes into distinct snapshots---a practice that makes it possible to
-track the *meaningful* progression of a software project (instead of
+track the _meaningful_ progression of a software project (instead of
just arbitrary lines of code).
## Commit the Snapshot {#the-basics.xhtml_commit-the-snapshot}
@@ -342,7 +347,7 @@ We have staged a snapshot, but we still need to **commit** it to the
project history. The next command will open a text editor and prompt you
to enter a message for the commit.
-``` k
+```k
git commit
```
@@ -354,8 +359,8 @@ file is our `index.html`.
As we just demonstrated, saving a version of your project is a two step
process:
-1. **Staging.** Telling Git what files to include in the next commit.
-2. **Committing.** Recording the staged snapshot with a descriptive
+1. **Staging.** Telling Git what files to include in the next commit.
+2. **Committing.** Recording the staged snapshot with a descriptive
message.
Staging files with the `git add` command doesn't actually affect the
@@ -367,23 +372,23 @@ means you can do almost anything you want to your project without losing
those "safe" revisions. This is the principal goal of any version
control system.
-
+
## View the Repository History {#the-basics.xhtml_view-the-repository-history}
Note that `git status` now tells us that there is `nothing to commit`,
which means our current state matches what is stored in the repository.
-The `git status` command will *only* show us uncommitted changes---to
+The `git status` command will _only_ show us uncommitted changes---to
view our project history, we need a new command:
-``` k
+```k
git log
```
When you execute this command, Git will output information about our one
and only commit, which should look something like this:
-``` k
+```k
commit b650e4bd831aba05fa62d6f6d064e7ca02b5ee1b
Author: unknown
Date: Wed Jan 11 00:45:10 2012 -0600
@@ -410,7 +415,7 @@ in the previous step.
Before committing any more snapshots, we should probably tell Git who we
are. We can do this with the `git config` command:
-``` k
+```k
git config --global user.name "Your Name"
git config --global user.email your.email@example.com
```
@@ -426,7 +431,7 @@ which will come in handy later on.
Let's continue developing our website a bit. Start by creating a file
called `orange.html` with the following content.
-``` cp
+```cp
@@ -443,7 +448,7 @@ called `orange.html` with the following content.
Then, add a `blue.html` page:
-``` cp
+```cp
@@ -461,7 +466,7 @@ Then, add a `blue.html` page:
Next, we can stage the files the same way we created the first snapshot.
-``` k
+```k
git add orange.html blue.html
git status
```
@@ -469,7 +474,7 @@ git status
Notice that we can pass more than one file to `git add`. After adding
the files, your status output should look like the following:
-``` c
+```c
# On branch master
# Changes to be committed:
# (use "git reset HEAD ..." to unstage)
@@ -480,17 +485,17 @@ the files, your status output should look like the following:
Try running `git log`. It only outputs the first commit, which tells us
that `blue.html` and `orange.html` have not yet been added to the
-repository's history. Remember, we can see *staged* changes with
+repository's history. Remember, we can see _staged_ changes with
`git status`, but not with `git log`. The latter is used only for
-*committed* changes.
+_committed_ changes.
-
+
## Commit the New Files {#the-basics.xhtml_commit-the-new-files}
Let's commit our staged snapshot:
-``` k
+```k
git commit
```
@@ -499,7 +504,7 @@ close the file. Now, `git log` should output two commits, the second of
which reflects our name/email configuration. This project history can be
visualized as:
-
+
Each circle represents a commit, the red circle designates the commit
we're currently viewing, and the arrow points to the preceding commit.
@@ -510,11 +515,11 @@ this tutorial.
## Modify the HTML Pages {#the-basics.xhtml_modify-the-html-pages}
-The `git add` command we've been using to stage *new* files can also be
-used to stage *modified* files. Add the following to the bottom of
+The `git add` command we've been using to stage _new_ files can also be
+used to stage _modified_ files. Add the following to the bottom of
`index.html`, right before the closing `` tag:
-``` nt
+```nt
Navigation
@@ -529,7 +534,7 @@ used to stage *modified* files. Add the following to the bottom of
Next, add a home page link to the bottom of `orange.html` and
`blue.html` (again, before the `` line):
-``` nt
+```nt
```
@@ -539,7 +544,7 @@ You can now navigate between pages when viewing them in a web browser.
Once again, we'll stage the modifications, then commit the snapshot.
-``` k
+```k
git status
git add index.html orange.html blue.html
git status
@@ -554,7 +559,7 @@ Our history can now be represented as the following. Note that the red
circle, which represents the current commit, automatically moves forward
every time we commit a new snapshot.
-
+
## Explore the Repository[']{.apo}s History {#the-basics.xhtml_explore-the-repository}
@@ -562,7 +567,7 @@ The `git log` command comes with a lot of formatting options, a few of
which will be introduced throughout this tutorial. For now, we'll just
use the convenient `--oneline` flag:
-``` k
+```k
git log --oneline
```
@@ -570,7 +575,7 @@ Condensing output to a single line is a great way to get a high-level
overview of a repository. Another useful configuration is to pass a
filename to `git log`:
-``` k
+```k
git log --oneline blue.html
```
@@ -584,7 +589,7 @@ In this module, we introduced the fundamental Git workflow: edit files,
stage a snapshot, and commit the snapshot. We also had some hands-on
experience with the components involved in this process:
-
+
The distinction between the working directory, the staged snapshot, and
committed snapshots is at the very core of Git version control. Nearly
@@ -599,25 +604,25 @@ simple versioning tool for your own projects.
## Quick Reference {#the-basics.xhtml_quick-reference}
`git init`
-: Create a Git repository in the current folder.
+: Create a Git repository in the current folder.
`git status`
-: View the status of each file in a repository.
+: View the status of each file in a repository.
`git add `
-: Stage a file for the next commit.
+: Stage a file for the next commit.
`git commit`
-: Commit the staged files with a descriptive message.
+: Commit the staged files with a descriptive message.
`git log`
-: View a repository's commit history.
+: View a repository's commit history.
`git config --global user.name ""`
-: Define the author name to be used in all repositories.
+: Define the author name to be used in all repositories.
`git config --global user.email `
-: Define the author email to be used in all repositories.
+: Define the author email to be used in all repositories.
:::
::::
@@ -625,6 +630,7 @@ simple versioning tool for your own projects.
:::::: {#undoing-changes.xhtml_page}
::::: {#undoing-changes.xhtml_content}
+
# Undoing Changes {#undoing-changes.xhtml_undoing-changes}
In the last module, we learned how to record versions of a project into
@@ -638,7 +644,7 @@ to restore them. Our next task is to learn how to view the previous
states of a project, revert back to them, and reset uncommitted changes.
::: {.icon-text .download-icon-text}
-{style="max-width: 45px"}
+{style="max-width: 45px"}
[Download the repository for this
module](http://rypress.com/tutorials/git/media/repo-zips/undoing-changes.zip)
@@ -657,14 +663,14 @@ As a quick review, let's display our repository's history. Navigate a
command prompt (or Git Bash) to the `my-git-repo` folder and run the
following.
-``` k
+```k
git log --oneline
```
The output for this should look similar to the following, but contain
different commit checksums.
-``` s
+```s
1c310d2 Add navigation links
54650a3 Create blue and orange pages
b650e4b Create index page
@@ -679,9 +685,9 @@ commit.
Using the new `git checkout` command, we can view the contents of a
previous snapshot. Make sure to change `54650a3` in the following
-command to the ID of your *second* commit.
+command to the ID of your _second_ commit.
-``` k
+```k
git checkout 54650a3
```
@@ -697,40 +703,40 @@ the project. After checking out the second commit, our repository
history looks like the following (the red circle represents the current
commit).
-
+
## View an Older Revision {#undoing-changes.xhtml_view-an-older-revision}
Let's go even farther back in our history. Be sure to change `b650e4b`
-to the ID of your *first* commit.
+to the ID of your _first_ commit.
-``` k
+```k
git checkout b650e4b
```
Now, the `blue.html` and `orange.html` files are gone, as is the rest of
the `git log` history.
-
+
In the last module, we said that Git was designed to never lose a
committed snapshot. So, where did our second and third snapshots go? A
simple `git status` will answer that question for us. It should return
the following message:
-``` c
+```c
# Not currently on any branch.
nothing to commit (working directory clean)
```
Compare this with the status output from the previous module:
-``` c
+```c
# On branch master
nothing to commit (working directory clean)
```
-All of our actions in *The Basics* took place on the `master` branch,
+All of our actions in _The Basics_ took place on the `master` branch,
which is where our second and third commits still reside. To retrieve
our complete history, we just have to check out this branch. This is a
very brief introduction to branches, but it's all we need to know to
@@ -742,7 +748,7 @@ detail.
We can use the same `git checkout` command to return to the `master`
branch.
-``` k
+```k
git checkout master
```
@@ -752,14 +758,14 @@ This makes Git update our working directory to reflect the state of the
as well. We're now back to the current state of the project, and our
history looks like:
-
+
## Tag a Release {#undoing-changes.xhtml_tag-a-release}
Let's call this a stable version of the example website. We can make it
official by **tagging** the most recent commit with a version number.
-``` k
+```k
git tag -a v1.0 -m "Stable version of the website"
```
@@ -780,7 +786,7 @@ We're now free to add experimental changes to the example site without
affecting any committed content. Create a new file called `crazy.html`
and add the following HTML.
-``` cp
+```cp
@@ -791,7 +797,7 @@ and add the following HTML.
@@ -801,7 +807,7 @@ and add the following HTML.
Stage and commit the new file as usual.
-``` k
+```k
git add crazy.html
git status
git commit -m "Add a crazzzy experiment"
@@ -824,7 +830,7 @@ Let's go back and take a look at our stable revision. Remember that the
`v1.0` tag now serves as a user-friendly shortcut to the third commit's
ID.
-``` k
+```k
git checkout v1.0
```
@@ -834,14 +840,14 @@ the `master` branch. If we didn't, all of our updates would be on some
non-existent branch. As we'll discover next module, you should never
make changes directly to a previous revision.
-``` k
+```k
git checkout master
git log --oneline
```
At this point, our history should look like the following:
-``` s
+```s
514fbe7 Add a crazzzy experiment
1c310d2 Add navigation links
54650a3 Create blue and orange pages
@@ -851,10 +857,10 @@ b650e4b Create index page
## Undo Committed Changes {#undoing-changes.xhtml_undo-committed-changes}
We're ready to restore our stable tag by removing the most recent
-commit. Make sure to change `514fbe7` to the ID of the *crazy
-experiment's commit* before running the next command.
+commit. Make sure to change `514fbe7` to the ID of the _crazy
+experiment's commit_ before running the next command.
-``` k
+```k
git revert 514fbe7
```
@@ -863,7 +869,7 @@ This will prompt you for a commit message with a default of
message and close the file. After verifying that `crazy.html` is gone,
take a look at your history with `git log --oneline`.
-``` s
+```s
506bb9b Revert "Add a crazzzy experiment"
514fbe7 Add a crazzzy experiment
1c310d2 Add navigation links
@@ -875,10 +881,10 @@ Notice that instead of deleting the "crazzzy experiment" commit, Git
figures out how to undo the changes it contains, then tacks on another
commit with the resulting content. So, our fifth commit and our third
commit represent the exact same snapshot, as shown below. Again, Git is
-designed to *never* lose history: the fourth snapshot is still
+designed to _never_ lose history: the fourth snapshot is still
accessible, just in case we want to continue developing it.
-
+
When using `git revert`, remember to specify the commit that you want to
undo---not the stable commit that you want to return to. It helps to
@@ -891,7 +897,7 @@ Let's try a smaller experiment this time. Create `dummy.html` and leave
it as a blank file. Then, add a link in the "Navigation" section of
`index.html` so that it resembles the following.
-``` nt
+```nt
Navigation
@@ -915,18 +921,18 @@ can't use the method discussed above.
Before we start undoing things, let's take a look at the status of our
repository.
-``` k
+```k
git status
```
We have a tracked file and an untracked file that need to be changed.
First, we'll take care of `index.html`:
-``` k
+```k
git reset --hard
```
-This changes all *tracked* files to match the most recent commit. Note
+This changes all _tracked_ files to match the most recent commit. Note
that the `--hard` flag is what actually updates the file. Running
`git reset` without any flags will simply unstage `index.html`, leaving
its contents as is. In either case, `git reset` only operates on the
@@ -937,17 +943,17 @@ Next, let's remove the `dummy.html` file. Of course, we could manually
delete it, but using Git to reset changes eliminates human errors when
working with several files in large teams. Run the following command.
-``` k
+```k
git clean -f
```
-This will remove all *untracked* files. With `dummy.html` gone,
+This will remove all _untracked_ files. With `dummy.html` gone,
`git status` should now tell us that we have a "clean" working
directory, meaning our project matches the most recent commit.
-***Be careful*** with `git reset` and `git clean`. Both operate on the
+**_Be careful_** with `git reset` and `git clean`. Both operate on the
working directory, not on the committed snapshots. Unlike `git revert`,
-they ***permanently*** undo changes, so make sure you really want to
+they **_permanently_** undo changes, so make sure you really want to
trash what you're working on before you use them.
## Conclusion {#undoing-changes.xhtml_conclusion}
@@ -960,7 +966,7 @@ undoes changes to the working directory and the staged snapshot, while
surprisingly, `git status` and `git log` directly parallel this
behavior.
-
+
I mentioned that instead of completely removing a commit, `git revert`
saves the commit in case you want to come back to it later. This is only
@@ -978,22 +984,22 @@ cover the basic Git branch commands.
## Quick Reference {#undoing-changes.xhtml_quick-reference}
`git checkout `
-: View a previous commit.
+: View a previous commit.
`git tag -a -m ""`
-: Create an annotated tag pointing to the most recent commit.
+: Create an annotated tag pointing to the most recent commit.
`git revert `
-: Undo the specified commit by applying a new commit.
+: Undo the specified commit by applying a new commit.
`git reset --hard`
-: Reset *tracked* files to match the most recent commit.
+: Reset _tracked_ files to match the most recent commit.
`git clean -f`
-: Remove *untracked* files.
+: Remove _untracked_ files.
-`git reset --hard` / ` git clean -f`
-: Permanently undo uncommitted changes.
+`git reset --hard` / `git clean -f`
+: Permanently undo uncommitted changes.
:::::
::::::
@@ -1001,18 +1007,19 @@ cover the basic Git branch commands.
:::::: {#branches-1.xhtml_page}
::::: {#branches-1.xhtml_content}
+
# Branches, Part I {#branches-1.xhtml_branches-part-i}
Branches are the final component of Git version control. This gives us
four core elements to work with throughout the rest of this tutorial:
-- The Working Directory
-- The Staged Snapshot
-- Committed Snapshots
-- Development Branches
+- The Working Directory
+- The Staged Snapshot
+- Committed Snapshots
+- Development Branches
In Git, a **branch** is an independent line of development. For example,
-if you wanted to experiment with a new idea *without* using Git, you
+if you wanted to experiment with a new idea _without_ using Git, you
might copy all of your project files into another directory and start
making your changes. If you liked the result, you could copy the
affected files back into the original project. Otherwise, you would
@@ -1028,7 +1035,7 @@ collaborative development, which will be explored in the latter half of
the tutorial.
::: {.icon-text .download-icon-text}
-{style="max-width: 45px"}
+{style="max-width: 45px"}
[Download the repository for this
module](http://rypress.com/tutorials/git/media/repo-zips/branches-1.zip)
@@ -1046,7 +1053,7 @@ from the above link, uncompress it, and you're good to go.
Let's start our exploration by listing the existing branches for our
project.
-``` k
+```k
git branch
```
@@ -1055,7 +1062,7 @@ branch is Git's default branch, and the asterisk next to it tells us
that it's currently checked out. This means that the most recent
snapshot in the `master` branch resides in the working directory:
-
+
Notice that since there's only one working directory for each project,
only one branch can be checked out at a time.
@@ -1066,13 +1073,13 @@ The previous module left out some details about how checking out
previous commits actually works. We're now ready to tackle this topic in
depth. First, we need the checksums of our committed snapshots.
-``` k
+```k
git log --oneline
```
This outputs the following history.
-``` s
+```s
506bb9b Revert "Add a crazzzy experiment"
514fbe7 Add a crazzzy experiment
1c310d2 Add navigation links
@@ -1083,7 +1090,7 @@ b650e4b Create index page
Check out the crazy experiment from the last module, remembering to
change `514fbe7` to the ID of your fourth commit.
-``` k
+```k
git checkout 514fbe7
```
@@ -1095,7 +1102,7 @@ diagrams actually represents Git's `HEAD`. The following figure shows
the state of our repository before and after we checked out an old
commit.
-
+
As shown in the "before" diagram, the `HEAD` normally resides on the tip
of a development branch. But when we checked out the previous commit,
@@ -1110,24 +1117,24 @@ We can't add new commits when we're not on a branch, so let's create one
now. This will take our current working directory and fork it into a new
branch.
-``` k
+```k
git branch crazy
```
Note that `git branch` is a versatile command that can be used to either
-list branches or create them. However, the above command only *creates*
+list branches or create them. However, the above command only _creates_
the `crazy` branch---it doesn't check it out.
-``` k
+```k
git checkout crazy
```
We're now free to experiment in the working directory without disturbing
-anything in the `master` branch. The `crazy` branch is a *completely
-isolated* development environment that can be visualized as the
+anything in the `master` branch. The `crazy` branch is a _completely
+isolated_ development environment that can be visualized as the
following.
-
+
Right now, the `crazy` branch, `HEAD`, and working directory are the
exact same as the fourth commit. But as soon as we add another snapshot,
@@ -1138,7 +1145,7 @@ we'll see a fork in our project history.
We'll continue developing our crazy experiment by changing `crazy.html`
to the following.
-``` cp
+```cp
@@ -1158,7 +1165,7 @@ to the following.
@@ -1169,7 +1176,7 @@ to the following.
Hopefully, you're relatively familiar with staging and committing
snapshots by now:
-``` k
+```k
git add crazy.html
git status
git commit -m "Add a rainbow to crazy.html"
@@ -1178,7 +1185,7 @@ git commit -m "Add a rainbow to crazy.html"
After committing on the `crazy` branch, we can see two independent lines
of development in our project:
-
+
Also notice that the `HEAD` (designated by the red circle) automatically
moved forward to the new commit, which is intuitively what we would
@@ -1187,7 +1194,7 @@ expect when developing a project.
The above diagram represents the complete state of our repository, but
`git log` only displays the history of the current branch:
-``` s
+```s
677e0e0 Add a rainbow to crazy.html
514fbe7 Add a crazzzy experiment
*1c310d2 Add navigation links
@@ -1195,14 +1202,14 @@ The above diagram represents the complete state of our repository, but
*b650e4b Create index page
```
-Note that the history *before* the fork is considered part of the new
+Note that the history _before_ the fork is considered part of the new
branch (marked with asterisks above). That is to say, the `crazy`
history spans all the way back to the first commit:
-
+
The project as a whole now has a complex history; however, each
-individual branch still has a *linear* history (snapshots occur one
+individual branch still has a _linear_ history (snapshots occur one
after another). This means that we can interact with branches in the
exact same way as we learned in the first two modules.
@@ -1212,7 +1219,7 @@ Let's add one more snapshot to the `crazy` branch. Rename `crazy.html`
to `rainbow.html`, then use the following Git commands to update the
repository.
-``` k
+```k
git status
git rm crazy.html
git status
@@ -1228,7 +1235,7 @@ file.
Our snapshot is staged and ready to be committed:
-``` k
+```k
git commit -m "Rename crazy.html to rainbow.html"
git log --oneline
```
@@ -1237,13 +1244,13 @@ After this addition, our complete repository history looks like the
following. Remember that the `crazy` branch doesn't include any commits
in `master` after the fork.
-
+
## Return to the Master Branch {#branches-1.xhtml_return-to-the-master-branch}
Let's switch back to the `master` branch:
-``` k
+```k
git checkout master
git branch
git log --oneline
@@ -1251,12 +1258,12 @@ git log --oneline
After the checkout, `crazy.html` doesn't exist in the working directory,
and the commits from the last few steps don't appear in the history.
-These two branches became *completely independent* development
+These two branches became _completely independent_ development
environments after they forked. You can think of them as separate
project folders that you switch between with `git checkout`. They do,
however, share their first four commits.
-
+
## Create a CSS Branch {#branches-1.xhtml_create-a-css-branch}
@@ -1268,7 +1275,7 @@ the Git commands used to manage them.
Let's create and check out a new branch called `css`.
-``` k
+```k
git branch css
git checkout css
```
@@ -1276,14 +1283,14 @@ git checkout css
The new branch points to the currently checked out snapshot, which
happens to coincide with the `master` branch:
-
+
## Add a CSS Stylesheet {#branches-1.xhtml_add-a-css-stylesheet}
Next, create a file called `style.css` with the following content. This
CSS is used to apply formatting to the HTML in our other files.
-``` nt
+```nt
body {
padding: 20px;
font-family: Verdana, Arial, Helvetica, sans-serif;
@@ -1302,7 +1309,7 @@ ul {
Commit the stylesheet in the usual fashion.
-``` k
+```k
git add style.css
git status
git commit -m "Add CSS stylesheet"
@@ -1317,13 +1324,13 @@ We still need to tell the HTML pages to use the formatting in
should be able to see the CSS formatting by opening `index.html` in a
web browser.
-``` nt
+```nt
```
Commit the changes.
-``` k
+```k
git add index.html blue.html orange.html
git status
git commit -m "Link HTML pages to stylesheet"
@@ -1332,7 +1339,7 @@ git log --oneline
This results in a repository history that looks like:
-
+
## Return to the Master Branch (Again) {#branches-1.xhtml_return-to-the-master-branch-again}
@@ -1341,7 +1348,7 @@ threatening the stability of the `master` branch. But, now we need to
merge these changes into the main project. Before we attempt the merge,
we need to return to the `master` branch.
-``` k
+```k
git checkout master
```
@@ -1349,11 +1356,11 @@ Verify that `style.css` doesn't exist and that HTML pages aren't linked
to it. Our repository history remains unchanged, but the working
directory now matches the snapshot pointed to by the `master` branch.
-
+
Take a look at the `git log --oneline` output as well.
-``` s
+```s
af23ff4 Revert "Add a crazzzy experiment"
a50819f Add a crazzzy experiment
4cd95d9 Add navigation links
@@ -1369,7 +1376,7 @@ As expected, there is no mention of the CSS additions in the history of
Use the `git merge` command to take the snapshots from the `css` branch
and add them to the `master` branch.
-``` k
+```k
git merge css
```
@@ -1377,13 +1384,13 @@ Notice that this command always merges into the current branch: `css`
remains unchanged. Check the history to make sure that the `css` history
has been added to `master`.
-``` k
+```k
git log --oneline
```
The following diagram visualizes the merge.
-
+
Instead of re-creating the commits in `css` and adding them to the
history of `master`, Git reuses the existing snapshots and simply moves
@@ -1399,7 +1406,7 @@ we're free to get rid of it.
We can safely delete a branch by passing the `-d` flag to `git branch`.
-``` k
+```k
git branch -d css
git branch
```
@@ -1409,7 +1416,7 @@ the same, though the `css` branch has been removed. I've also put the
`master` branch's commits in a straight line in the following
visualization, making it easier to track during the upcoming modules.
-
+
Deleting branches is a relatively "safe" operation in the sense that Git
will warn you if you're deleting an unmerged branch. This is just
@@ -1439,24 +1446,24 @@ complicated merges than the fast-forward merge introduced above.
## Quick Reference {#branches-1.xhtml_quick-reference}
`git branch`
-: List all branches.
+: List all branches.
`git branch `
-: Create a new branch using the current working directory as its base.
+: Create a new branch using the current working directory as its base.
`git checkout `
-: Make the working directory and the `HEAD` match the specified
- branch.
+: Make the working directory and the `HEAD` match the specified
+branch.
`git merge `
-: Merge a branch into the checked-out branch.
+: Merge a branch into the checked-out branch.
`git branch -d `
-: Delete a branch.
+: Delete a branch.
`git rm `
-: Remove a file from the working directory (if applicable) and stop
- tracking the file.
+: Remove a file from the working directory (if applicable) and stop
+tracking the file.
:::::
::::::
@@ -1464,6 +1471,7 @@ complicated merges than the fast-forward merge introduced above.
:::::: {#branches-2.xhtml_page}
::::: {#branches-2.xhtml_content}
+
# Branches, Part II {#branches-2.xhtml_branches-part-ii}
Now that we've covered the mechanics behind Git branches, we can discuss
@@ -1487,7 +1495,7 @@ situation may also give rise to a merge conflict, which must be manually
resolved before anything can be committed to the repository.
::: {.icon-text .download-icon-text}
-{style="max-width: 45px"}
+{style="max-width: 45px"}
[Download the repository for this
module](http://rypress.com/tutorials/git/media/repo-zips/branches-2.zip)
@@ -1504,7 +1512,7 @@ from the above link, uncompress it, and you're good to go.
Let's start by checking out the `crazy` branch.
-``` k
+```k
git branch
git checkout crazy
git log --oneline
@@ -1512,15 +1520,15 @@ git log --oneline
The `crazy` branch is a longer-running type of topic branch called a
**feature branch**. This is fitting, as it was created with the
-intention of developing a specific *feature*. It's also a term that
+intention of developing a specific _feature_. It's also a term that
makes Git's contribution to the development workflow readily apparent:
branches enable you to focus on developing one clearly defined feature
at a time.
This brings us to my rule-of-thumb for using Git branches:
-- Create a new branch for each major addition to your project.
-- *Don't* create a branch if you can't give it a specific name.
+- Create a new branch for each major addition to your project.
+- _Don't_ create a branch if you can't give it a specific name.
Following these simple guidelines will have a dramatic impact on your
programming efficiency.
@@ -1530,11 +1538,11 @@ programming efficiency.
Note that the CSS formatting we merged into `master` is nowhere to be
found. This presents a bit of a problem if we want our experiment to
reflect these updates. Conveniently, Git lets us merge changes into
-*any* branch (not just the `master` branch). So, we can pull the updates
+_any_ branch (not just the `master` branch). So, we can pull the updates
in with the familiar `git merge` command. Remember that merging only
affects the checked-out branch.
-``` k
+```k
git merge master
git log --oneline
```
@@ -1547,7 +1555,7 @@ first merge didn't add any new commits; it just "fast-forwarded" the tip
of the `master` branch. This was not the case for our new merge, which
is shown below.
-
+
Take a moment to examine why the current merge couldn't be a
fast-forward one. How could Git have walked the `crazy` pointer over to
@@ -1557,14 +1565,14 @@ new way to combine branches: the **3-way merge**.
A 3-way merge occurs when you try to merge two branches whose history
has diverged. It creates an extra **merge commit** to function as a link
-between the two branches. As a result, it has *two* parent commits. The
+between the two branches. As a result, it has _two_ parent commits. The
above figure visualizes this with two arrows originating from the tip of
`crazy`. It's like saying "this commit comes from both the `crazy`
-branch *and* from `master`." After the merge, the `crazy` branch has
+branch _and_ from `master`." After the merge, the `crazy` branch has
access to both its history and the `master` history.
The name comes from the internal method used to create the merge commit.
-Git looks at *three* commits (numbered in the above figure) to generate
+Git looks at _three_ commits (numbered in the above figure) to generate
the final state of the merge.
This kind of branch interaction is a big part of what makes Git such a
@@ -1579,14 +1587,14 @@ continue developing our crazy experiment. Link the CSS stylesheet to
`rainbow.html` by adding the following HTML on the line after the
`` element.
-``` nt
+```nt
```
Stage and commit the update, then check that it's reflected in the
history.
-``` k
+```k
git status
git commit -a -m "Add CSS stylesheet to rainbow.html"
git log --oneline
@@ -1594,7 +1602,7 @@ git log --oneline
Notice that we skipped the staging step this time around. Instead of
using `git add`, we passed the `-a` flag to `git commit`. This
-convenient parameter tells Git to automatically include *all* tracked
+convenient parameter tells Git to automatically include _all_ tracked
files in the staged snapshot. Combined with the `-m` flag, we can stage
and commit snapshots with a single command. However, be careful not to
include unintended files when using the `-a` flag.
@@ -1604,7 +1612,7 @@ include unintended files when using the `-a` flag.
We still need to add a navigation link to the home page. Change the
"Navigation" section of `index.html` to the following.
-``` nt
+```nt
Navigation
@@ -1621,7 +1629,7 @@ We still need to add a navigation link to the home page. Change the
As usual, stage and commit the snapshot.
-``` k
+```k
git commit -a -m "Link index.html to rainbow.html"
git log --oneline
```
@@ -1632,7 +1640,7 @@ Next, we're going to brainstorm an alternative to the current
`rainbow.html` page. This is a perfect time to create another topic
branch:
-``` k
+```k
git branch crazy-alt
git checkout crazy-alt
```
@@ -1644,13 +1652,13 @@ we begin with the same files as `crazy` (if we called `git branch` from
`master`, we would have had to re-create `rainbow.html`). After creating
the new branch, our repository's history looks like:
-
+
## Change the Rainbow {#branches-2.xhtml_change-the-rainbow}
Change the colorful list in `rainbow.html` from:
-``` nt
+```nt
Red
Orange
@@ -1664,7 +1672,7 @@ Change the colorful list in `rainbow.html` from:
to the following:
-``` nt
+```nt
@@ -1677,7 +1685,7 @@ to the following:
Then, add some CSS formatting to `` on the line after the ``
element:
-``` nt
+```nt