Menu
Coddy logo textTech

Committing On A Branch

Part of the Version Control section of Coddy's Terminal journey — lesson 31 of 58.

Commits you make on a branch only affect that branch. The main branch stays exactly where it was, untouched, until you decide to merge.

This is the core idea behind feature branches: try things on the side, leave main stable.

git switch -c feature-login
echo "login form" >> app.txt
git add app.txt
git commit -m "Start login form"

Now feature-login has one extra commit, while main is unchanged. You can switch back any time and the working files revert to the main version:

git switch main
cat app.txt    # original content, no "login form" line

The branches are independent timelines until you bring them back together.

challenge icon

Challenge

Easy

The repo has one commit on main with a file data.txt containing the line v1.

Create and switch to a branch called edits, overwrite data.txt with v2, and commit with the message Bump to v2. Then switch back to main and print the contents of data.txt.

The expected output shows the original v1 (unchanged on main).

Cheat sheet

Commits on a branch only affect that branch. main stays untouched until you merge.

# Create branch, make changes, commit
git switch -c feature-login
echo "login form" >> app.txt
git add app.txt
git commit -m "Start login form"

# Switch back — working files revert to main's version
git switch main

Branches are independent timelines: feature-login has the new commit, main does not.

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Version Control