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" lineThe branches are independent timelines until you bring them back together.
Challenge
EasyThe 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 mainBranches are independent timelines: feature-login has the new commit, main does not.
Try it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Version Control
7Branching
What Is A BranchCreating A BranchSwitching BranchesCommitting On A BranchDeleting A BranchRecap - Branch Play2Getting Started
Initialize A RepositoryThe .git FolderConfigure Your IdentityGit StatusRecap - First Repo8Merging
What Is A MergeFast-Forward MergeThree-Way MergeMerge ConflictsResolve A ConflictRecap - Merge Master11Feature Branch Project
Project OverviewInitialize Main3Tracking Changes
The Staging AreaGit AddGit CommitModifying A Tracked FileGit LogRecap - First Commits6Recipe Site Project
Project OverviewInitialize And Ignore