0%

Branches · practice

Move the Branch with a Commit

Your current is add-opening-hours, but it still points to the same as main. Now you will make one commit and watch only the current branch move.

Add the opening-hours file

Open a new file with nano:

nano -w hours.txt

nano is the editor used throughout this course. The -w option stops nano from inserting hard line breaks merely because the terminal is narrow.

Type this one line:

Opening hours: 9:00 to 17:00.

Save with Ctrl-O, press Enter to confirm hours.txt, and leave with Ctrl-X. If you need the fuller nano walkthrough, Chapter 2’s first lesson, Edit a File in the Terminal, explains every control from a blank screen.

Commit on the current branch

The next three commands use the same edit-stage-commit path you learned in Chapter 2. git status lets you inspect the untracked file, git add hours.txt puts its current contents into the , and git commit -m records the staged snapshot with the quoted message.

git status
git add hours.txt
git commit -m "Add opening hours"

Git makes the new commit after Clarify the guide title. Because HEAD follows add-opening-hours, that branch pointer moves forward to the new commit. main and clearer-title do not move.

Add opening hours             <- add-opening-hours (HEAD)
        |
Clarify the guide title       <- main, clearer-title
        |
Start the neighborhood guide

Read the result

Run the two simplest reading commands:

git log
git branch

git log reads backward from the current branch, so Add opening hours is newest and the two seeded commits follow it. Plain git branch still marks add-opening-hours with *.

The other branch names are not printed beside individual commits by plain git log, and this lesson does not add a compact display option to make them appear. The important model is already enough: a commit advances the branch that HEAD follows, while the other branch pointers stay where they were.

After committing on add-opening-hours, where does main point?

That is the rule that makes branches useful, and it is worth saying plainly: a commit moves the branch you are standing on, and leaves every other branch exactly where it was. Your opening-hours work exists, and main still knows nothing about it.

Which raises a fair question. If main has no hours.txt, what happens to the file on disk when you go back to main?