0%

Chapter 2 · practice

Your First Repository

Edit a File in the Terminal

You have a file to change, and the only tool open in front of you is a . That is enough. In this course, the editor inside the terminal is GNU nano, and you will use the same editor whenever a Git lesson asks you to change a file. Vim is also available, but this course keeps nano as the taught path.

Open a file

In the terminal beside this lesson, run:

nano -w README.md

If README.md does not exist yet, nano creates it when you save. The -w means that nano does not hard-wrap long lines while you are editing. It helps keep the bytes you type separate from the way a narrow terminal displays them.

Type these two lines of text with a blank line between them:

# Garden notes

The first repository will keep this file's history.

The bottom two lines of nano show its most useful controls. A caret means the Ctrl key. For example, ^O means Ctrl-O.

Save, then leave

Save the buffer with:

  1. Press Ctrl-O.

  2. Nano shows File Name to Write: README.md. Press Enter to accept that name.

  3. Press Ctrl-X to leave nano.

Back at the , check what was written:

cat README.md

The terminal prints the same two lines. You edited a real file in /workspace; nothing was copied into a separate project editor.

If you get stuck

Nano asks a question at the bottom of the screen instead of accepting normal typing. Ctrl-C cancels the current question and returns you to the buffer.

If you want to abandon the changes, press Ctrl-X, then N when nano asks whether to save. The old file stays as it was. If you saved by mistake, leave nano and reopen the file with nano -w README.md; the next lesson will show how Git gives you another way to inspect and undo changes after the exists.

The safe habit is simple: save deliberately, confirm the filename, then exit. Do not close the browser tab while nano still has changes that you need.

You have finished editing README.md and want the text to reach the file. Which sequence saves it and leaves nano?

The next lesson will put this file under version control. First you will tell Git who is making the , then you will make the repository and record its first snapshot.