You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _episodes/02-getting-started.md
+33-33Lines changed: 33 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,18 +18,18 @@ keypoints:
18
18
19
19
### Using Git
20
20
21
-
One of the main barriers to getting started with git is the language. Although some of the language used in git is
22
-
fairly self-explanatory, other terms are not so clear. The best way to get to learn the language - which consists of a
23
-
number of verbs such as `add`, `commit` and `push` (preceded by the word 'git') - is by using it, which is what we will be doing during this
24
-
lesson. These commands will be explained as we proceed from setting up a new version-controlled project to publishing
21
+
One of the main barriers to getting started with git is the language. Although some of the language used in git is
22
+
fairly self-explanatory, other terms are not so clear. The best way to get to learn the language - which consists of a
23
+
number of verbs such as `add`, `commit` and `push` (preceded by the word 'git') - is by using it, which is what we will be doing during this
24
+
lesson. These commands will be explained as we proceed from setting up a new version-controlled project to publishing
25
25
our own website.
26
26
27
27
28
28
### Creating a repository
29
29
30
-
A Git **repository** is a data structure used to track changes to a set of project files over time. Repositories are
31
-
stored within the same directory as these project files, in a hidden directory called `.git`. We can create a new git
32
-
repository either by using [GitHub's web interface](https://github.com/new), or via the command line. Let's use the command line to create a git
30
+
A Git **repository** is a data structure used to track changes to a set of project files over time. Repositories are
31
+
stored within the same directory as these project files, in a hidden directory called `.git`. We can create a new git
32
+
repository either by using [GitHub's web interface](https://github.com/new), or via the command line. Let's use the command line to create a git
33
33
repository for the experiments that we're going to do today.
34
34
35
35
First, we will create a new directory for our project and enter that directory.
@@ -39,29 +39,29 @@ First, we will create a new directory for our project and enter that directory.
39
39
$ mkdir hello-world
40
40
$ cd hello-world
41
41
~~~
42
-
{: .bash}
42
+
{: .language-bash}
43
43
44
-
We will now create an empty git repository to track changes to our project. To do this we will use the git **init** command,
44
+
We will now create an empty git repository to track changes to our project. To do this we will use the git **init** command,
45
45
which is simply short for *initialise*.
46
46
47
47
~~~
48
48
$ git init
49
49
~~~
50
-
{: .bash}
50
+
{: .language-bash}
51
51
~~~
52
52
Initialized empty Git repository in <your file path>/hello-world/.git/
53
53
~~~
54
54
{: .output}
55
55
56
56
57
-
The `hello-world` directory is now a git repository.
57
+
The `hello-world` directory is now a git repository.
58
58
59
-
If we run the `ls` command now (`ls` lists the content of the `hello-world`
60
-
directory), the repository might seem empty; however, adding the `-a` flag
61
-
for all files via `ls -a` will show all hidden files, which in this case
59
+
If we run the `ls` command now (`ls` lists the content of the `hello-world`
60
+
directory), the repository might seem empty; however, adding the `-a` flag
61
+
for all files via `ls -a` will show all hidden files, which in this case
62
62
includes the new hidden directory `.git`. Flags can simply be thought of as command line options that can be added to shell commands.
63
63
64
-
Note that whenever we use git via the command line, we need to preface each command (or verb) with `git`, so that the computer knows
64
+
Note that whenever we use git via the command line, we need to preface each command (or verb) with `git`, so that the computer knows
65
65
we are trying to get git to do something, rather than some other program.
66
66
67
67
### Displaying the current project's status
@@ -71,30 +71,30 @@ We can run the `git status` command to display the current state of a project. L
71
71
~~~
72
72
$ git status
73
73
~~~
74
-
{: .bash}
74
+
{: .language-bash}
75
75
~~~
76
76
On branch master
77
77
No commits yet
78
78
nothing to commit (create/copy files and use "git add" to track)
79
79
~~~
80
80
{: .output}
81
81
82
-
The output tells us that we are on the master branch (more on this later) and that we have nothing to commit (no
82
+
The output tells us that we are on the master branch (more on this later) and that we have nothing to commit (no
83
83
unsaved changes).
84
84
85
85
86
86
### Adding and committing
87
87
88
-
We will now create and save our first project file. This is a two-stage process. First, we **add** any files for which
89
-
we want to save the changes to a staging area, then we **commit** those changes to the repository. This two-stage
88
+
We will now create and save our first project file. This is a two-stage process. First, we **add** any files for which
89
+
we want to save the changes to a staging area, then we **commit** those changes to the repository. This two-stage
90
90
process gives us fine-grained control over what should and should not be included in a particular commit.
91
91
92
92
Let's create a new file using the `touch` command, which is a quick way to create an empty file.
93
93
94
94
~~~
95
95
$ touch index.md
96
96
~~~
97
-
{: .bash}
97
+
{: .language-bash}
98
98
99
99
The `.md` extension above signifies that we have chosen to use the Markdown format, a lightweight markup language with plain text formatting syntax. We will explore Markdown a bit later.
100
100
@@ -103,7 +103,7 @@ Let's check the status of our project again.
103
103
~~~
104
104
$ git status
105
105
~~~
106
-
{: .bash}
106
+
{: .language-bash}
107
107
~~~
108
108
On branch master
109
109
No commits yet
@@ -116,21 +116,21 @@ nothing added to commit but untracked files present (use "git add" to track)
116
116
~~~
117
117
{: .output}
118
118
119
-
This status is telling us that git has noticed a new file in our directory that we are not yet tracking. With colourised
120
-
output, the filename will appear in red. To change this, and to tell Git we want to track any changes we make to
119
+
This status is telling us that git has noticed a new file in our directory that we are not yet tracking. With colourised
120
+
output, the filename will appear in red. To change this, and to tell Git we want to track any changes we make to
121
121
index.md, we use `git add`.
122
122
123
123
~~~
124
124
$ git add index.md
125
125
~~~
126
-
{: .bash}
126
+
{: .language-bash}
127
127
128
128
This adds our Markdown file to the **staging area** (the area where git checks for file changes). To confirm this we want to use `git status` again.
129
129
130
130
~~~
131
131
$ git status
132
132
~~~
133
-
{: .bash}
133
+
{: .language-bash}
134
134
~~~
135
135
On branch master
136
136
@@ -153,7 +153,7 @@ has spotted the changes.
153
153
~~~
154
154
$ git status
155
155
~~~
156
-
{: .bash}
156
+
{: .language-bash}
157
157
~~~
158
158
On branch master
159
159
@@ -172,32 +172,32 @@ Changes not staged for commit:
172
172
~~~
173
173
{: .output}
174
174
175
-
This lets us know that git has indeed spotted the changes to our file, but that it hasn't yet staged them, so let's add
175
+
This lets us know that git has indeed spotted the changes to our file, but that it hasn't yet staged them, so let's add
176
176
the new version of the file to the staging area.
177
177
178
178
~~~
179
179
$ git add index.md
180
180
~~~
181
-
{: .bash}
181
+
{: .language-bash}
182
182
183
-
Now we are ready to **commit** our first changes.
184
-
Commit is similar to 'saving' a file to Git.
183
+
Now we are ready to **commit** our first changes.
184
+
Commit is similar to 'saving' a file to Git.
185
185
However, compared to saving, a commit provides a lot more information about the changes we have made,
186
186
and this information will remain visible to us later.
187
187
188
188
189
189
~~~
190
190
$ git commit -m 'Add index.md'
191
191
~~~
192
-
{: .bash}
192
+
{: .language-bash}
193
193
~~~
194
194
[master (root-commit) e9e8fd3] Add index.md
195
195
1 file changed, 1 insertion(+)
196
196
create mode 100644 index.md
197
197
~~~
198
198
{: .output}
199
199
200
-
We can see that one file has changed and that we made one insertion, which was a line with the text '#Hello, world!'.
200
+
We can see that one file has changed and that we made one insertion, which was a line with the text '#Hello, world!'.
201
201
We can
202
202
also see the commit message 'Add index.md', which we added by using the `-m` flag after `git commit`.
203
203
The commit message is used to record a short, descriptive, and specific summary of what we did to help us remember later on without having to look at the actual changes.
@@ -229,6 +229,6 @@ along with metadata about who made the commit and at what time.
0 commit comments