What Is A Branch
Part of the Version Control section of Coddy's Terminal journey — lesson 28 of 58.
A branch in Git is just a movable pointer to a commit. The default branch is usually called main, and every commit you make on it advances that pointer forward.
Branches let you work on different lines of development at the same time without stepping on each other. You can:
- Try out a risky idea on a side branch and abandon it cleanly
- Build a new feature in isolation while
mainstays stable - Hand off work to a teammate by sharing a branch
You can list branches at any time with:
git branchThe branch you are currently on is shown with a * next to its name. Internally, Git tracks "the current branch" through the .git/HEAD file you saw earlier.
Challenge
BeginnerThe folder is already a fully configured Git repo with one commit on the main branch. List the branches and print the result.
Cheat sheet
A branch in Git is a movable pointer to a commit. The default branch is usually called main.
List all branches with:
git branchThe current branch is marked with a *. Git tracks the current branch via the .git/HEAD file.
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