Skip to content

Commit c08601c

Browse files
committed
Convert beginner exercises to Markdown
1 parent 24ef303 commit c08601c

File tree

7 files changed

+547
-445
lines changed

7 files changed

+547
-445
lines changed

beginner/Markdowns/Exercise_1.md

Lines changed: 79 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,126 @@
11
## Exercise 1
22

3-
## Goals
4-
* Create Git repository from scratch
5-
* Track changes in files using `git add`, `git status` and `git commit`
6-
* Know state of Git repo using `git diff` and `git log`
3+
## Objective
4+
* Create a Git repository from scratch
5+
* Track changes to files using `git add`, `git status`, and `git commit`
6+
* Know the state of the Git repository using `git diff` and `git log`
77

88
## Structure
9-
This exercise consists of short descriptions about a specific git command, followed by a practical part where you can execute appropriate Git commands.
10-
In order to allow a smooth exercise, there are some functions written by C2SM in the file *helpers.sh* that are **NOT** part of Git. For this exercise we use the following functions from that file:
11-
* **init_exercise:** It will create the *work* directory and navigate into it
12-
* **reset:** It will delete the *work* folder and enable you a clean restart of the exercise in case you completely mess it up.
13-
14-
In the following (and all further exercises), all text enclosed with `<>` denotes a placeholder to be replaced by a specific string appropriate in **your** context.
9+
This exercise consists of short descriptions of specific Git commands, followed by a hands-on part where you will be able to execute the corresponding Git commands.
1510

16-
### Start exercises in correct folder
17-
This exercise (and all further exercises) assume that the shell is already located in the folder of the exercise notebooks. It could happen, for some reason, that the notebook does not by default switch to the folder of the notebook. In that case you need to manually change the directory first in order to do the exercises.
11+
## Helper Functions
12+
The following helper functions in the file *helpers.sh* are written by C2SM and are **NOT** **part of Git**. They will set up simple repositories for you that have a short Git history, so that you have something to work with.
1813

19-
If the command
14+
For this exercise, we will use the following functions from this file:
15+
* **init_exercise:** This will create the *beginners_git* directory in the parent directory of the *git-course* directory. It will also delete any old version of the *beginners_git* directory, so don't use the *beginners_git* directory to save any work.
16+
* **reset:** This will delete the *beginners_git* directory and allows you a clean restart of the exercise in case you messed it up completely.
2017

21-
`pwd`
22-
returns something similar to
23-
`/home/juckerj/git-course/Exercise_1`
24-
everything is fine.
2518

26-
In case it returns only
27-
`/home/juckerj`
28-
please go the right directory.
19+
## Remarks
20+
_**Note:** Any text enclosed in `<>` denotes a placeholder to be replaced with a specific string appropriate to your context, i.e. delete `<>` and replace it with the appropriate word._
21+
22+
_**Note:** The exercises require you to use basic Unix commands. If you are not familiar with Unix systems, we have listed all the necessary commands in the file [Basic Unix Commands](../Unix_Commands.ipynb)._
23+
2924

3025
### Initialization
3126

27+
**Start exercises in correct folder:**
28+
This exercise (and all the exercises that follow) assume that the shell is already in the folder where the exercise notebooks are located. For some reason, the notebook may not switch to the notebook folder by default. In this case, you will need to manually change the directory in order to complete the exercises.
29+
30+
If the `pwd` command returns something like `/home/juckerj/git-course/beginner/Exercise_1`, everything is fine.
31+
32+
If it returns something like `/home/juckerj`, change to the correct directory.
33+
34+
3235

3336
```bash
3437
# check current directory with "pwd"
35-
pwd
38+
3639
# go to folder of this exercise using "cd"
3740

3841
```
3942

43+
**To initialize the exercise properly, run this code at the very beginning. Check the Helper Functions section above for more explanation.**
44+
4045

4146
```bash
42-
# execute this code at the very beginning to initialize the exercise properly
47+
# source the helpers.sh file to be able to use its functions
4348
source ../helpers.sh
49+
# init exercise
4450
init_exercise
4551
```
4652

4753
***
4854
### Optional: clear notebook and restart
49-
**In case you mess up your notebook completely,
50-
execute** ***reset*** **in the following cell. This will restore a clean environment!**
55+
**In case you messed up your notebook completely, execute** ***reset*** **in the following cell. Check the Helper Functions section above for more explanation.**
5156

5257

5358
```bash
5459
## only execute in case of (serious) trouble ##
55-
## it will delete your entire work directory ##
60+
## it will delete your entire beginners_git directory ##
5661
reset
5762
```
5863

5964
***
6065
## Exercise
6166

6267
### Global Git configuration settings
63-
Before we start to use Git, we are specifying a few global configuration settings. This has to be done only once and will be saved for all your future sessions.
68+
Before we start using Git, we should set some global configurations. This only needs to be done once, and will be saved for all your future sessions.
6469

6570
First of all, we need to tell Git who we are.
66-
To do so, execute the lines below with your credentials:
71+
To do this, run the following lines with your credentials:
6772
```
6873
git config --global user.name "<John Doe>"
6974
git config --global user.email "<[email protected]>"
7075
```
71-
**Note:** The email must be identical to the one that is used for your Github account.
76+
**Note:** The email must be identical to the one that is used for your GitHub account.
7277

7378

7479
```bash
7580
# tell Git who you are
7681

82+
7783
```
7884

79-
At the end of this course, you will learn something about repository managers like Github. Recently, they changed their naming policy for the initial branch from 'master' to 'main'. Therefore, we want to tell Git to also set our default branch name to 'main'.
85+
At the end of this course, you will learn something about repository managers like GitHub. Recently, they changed their naming policy for the initial branch from *master* to *main*. So we want to tell Git to set our default branch name to *main* as well.
8086

81-
**Note:** Check out the official Git documentation (https://git-scm.com/docs/git-init#Documentation/git-init.txt--bltbranch-namegt).
87+
**Note:** See the official Git documentation (https://git-scm.com/docs/git-init#Documentation/git-init.txt--bltbranch-namegt).
8288

8389

8490
```bash
85-
# Set main as the default branch name
91+
# set 'main' as the default branch name
8692
git config --global init.defaultBranch main
8793
```
8894

8995
### Create Git repository from scratch
96+
> Hint: check the [Basic Unix Commands](../Unix_Commands.ipynb) if you don't know how to do the following.
9097
9198

9299
```bash
93-
# create new folder (e.g. <git_repo>) and enter it
100+
# create a new folder (e.g. <git_repo>) and navigate to it
94101

95102
```
96103

97104

98105
```bash
99-
# use the command "git init" to initiate your first Git-repository
100-
git init
106+
# use the command "git init" to initiate your first Git repository
107+
101108
```
102109

103-
You should now get an output similar to that:
110+
You should now get an output similar to:
104111
```
105-
Initialized empty Git repository in /Users/juckerj/Desktop/git_course/Exercise_1/work/git_repo/.git/
112+
Initialized empty Git repository in <parent-dir-of-git-course>/beginners_git/git_repo/.git/
106113
```
107-
### Track changes in files using git add and git commit
114+
### Make and track changes in files using `git add`, `git commit` and `git status`
108115

109-
In a next step you will add some files to you repository.
110-
To do so, we make use of the *echo* command in combination with the ">" operator to direct its
116+
In a next step you will add some files to your repository.
117+
To do this, we will use the *echo* command in combination with the ">" operator to direct its
111118
output to a file.
112119

113120

114121
```bash
115-
# to create a new file use the echo-command
116-
# echo "<my text for file>" > first_file
122+
# create a text file using the echo-command
123+
# echo "<my text for file>" > first_file.txt
117124

118125
```
119126

@@ -125,8 +132,7 @@ output to a file.
125132

126133

127134
```bash
128-
# check the status of your Git-repository with "git status"
129-
135+
# check the status of your Git repository with "git status"
130136

131137
```
132138

@@ -140,15 +146,14 @@ No commits yet
140146
141147
Untracked files:
142148
(use "git add <file>..." to include in what will be committed)
143-
first_file
144-
second_file
149+
first_file.txt
150+
second_file.txt
145151
146152
nothing added to commit but untracked files present (use "git add" to track)
147153
```
148154

149155

150-
Git recognized these two new files, but the files are not yet included in the repository.
151-
156+
Git has detected the two new files, but the files are not yet included in the Git repository.
152157

153158

154159
```bash
@@ -158,7 +163,7 @@ Git recognized these two new files, but the files are not yet included in the re
158163

159164
```
160165

161-
Your output should look as follows:
166+
Your output should look like this:
162167

163168
```
164169
On branch main
@@ -167,15 +172,15 @@ No commits yet
167172
168173
Changes to be committed:
169174
(use "git rm --cached <file>..." to unstage)
170-
new file: first_file
171-
new file: second_file
175+
new file: first_file.txt
176+
new file: second_file.txt
172177
```
173178

174179
The last thing to do is to commit these files.
175180

176181

177182
```bash
178-
# use 'git commit -m "<meaningful message>"'
183+
# use "git commit -m "<meaningful message>""
179184

180185
```
181186

@@ -184,21 +189,19 @@ Your files are included in the Git repository.
184189

185190

186191

187-
### Know state of Git repository using git diff and git log
188-
For now, we have two files in our Git repository.
189-
Let's see what happens when we modify them. We therefore use the ">>" operator to append a new line of text to our files.
192+
### Know state of Git repository using `git diff` and `git log`
193+
Right now we have two files in our Git repository.
194+
Let's see what happens when we modify them. We will use the ">>" operator to append a new line of text to our files.
190195

191196

192197
```bash
193-
# append a new line of text with "echo" and ">>"
194-
198+
# append a new line of text with "echo" and ">>" to one of the files
195199

196200
```
197201

198202

199203
```bash
200-
# check state of you repository with "git status"
201-
204+
# check state of your repository with "git status"
202205

203206
```
204207

@@ -209,20 +212,18 @@ On branch main
209212
Changes not staged for commit:
210213
(use "git add <file>..." to update what will be committed)
211214
(use "git restore <file>..." to discard changes in working directory)
212-
modified: first_file
215+
modified: first_file.txt
213216
214217
no changes added to commit (use "git add" and/or "git commit -a")
215218
```
216219

217220

218-
At some point you forget about the additional line we just added.
219-
Git provides a command to check, what new changes are contained in a file:
220-
**git diff**
221+
When working in a repository, it easily happens that you forget about changes you have made, such as the extra lines you just added.
222+
Git provides the `git diff` command to check, what new changes are contained in a file
221223

222224

223225
```bash
224-
# see local changes of modified file with "git diff your_filename"
225-
226+
# see local changes of a modified file with "git diff <your_filename>"
226227

227228
```
228229

@@ -231,57 +232,50 @@ In the output
231232
```
232233
diff --git a/first_file b/first_file
233234
index 3829ab8..a32d2f3 100644
234-
--- a/first_file
235-
+++ b/first_file
235+
--- a/first_file.txt
236+
+++ b/first_file.txt
236237
@@ -1 +1,2 @@
237238
myfirstline
238239
+mysecondline
239240
```
240241

241-
we see a lot of information. But all we care at the moment is the last line:
242-
The + indicates that we have a new line in our file.
242+
We see a lot of information, but all that we care about is the last line:
243+
The "+" indicates that we have a new line in our file.
243244

244245

245-
Because Git is so easy, we modify the second file as well.
246+
Let's modify the second file as well.
246247

247248

248249
```bash
249250
# add a new line in the second file as well
250251

251-
252252
```
253253

254-
The next lecture is starting soon, so let's add and commit our changes for safety reasons in Git.
254+
The next lecture is starting soon, so let's add and commit our changes for safety reasons.
255255

256256

257257
```bash
258-
# add you two modified files with "git add"
259-
260-
261-
# git status to check if your action was successful
258+
# add the two modified files with "git add"
262259

260+
# use "git status" to check if your action was successful
263261

264262
```
265263

266264

267265
```bash
268-
# use 'git commit -m "<meaningful message>"' to commit your files
269-
266+
# use "git commit -m "<meaningful message>"" to commit your files
270267

271268
```
272269

273270
**Congrats!**
274-
But how many commits do I already have in this repository?
271+
But how many commits do you already have in this repository?
275272
Git does all this tracking for us!
276273

277-
`git log` allows us to look back in time and explore what commits are contained in our repository.
278-
274+
The command `git log` allows us to look back in time and explore what commits are contained in our repository.
279275

280276

281277
```bash
282-
# type git log to get an overview of the (very short)
283-
# life of your repository
284-
278+
# type "git log" to get an overview of the (very short) life of your repository
285279

286280
```
287281

@@ -301,5 +295,5 @@ Date: Tue Feb 23 16:09:54 2021 +0100
301295
test
302296
```
303297

304-
We see the unique hash of each commit, its author as well as the date of the commit.
305-
Those are all very useful things as we will see later in this course.
298+
We see the unique hash of each commit, its author, and the date of the commit.
299+
These are all very useful things as we will see later in this course.

0 commit comments

Comments
 (0)