Branch

  • Standard term
3 steps

A branch is a named line of work in a Git project. It lets separate series of commits build up side by side, so each can be tried on its own and merged back in if it works out.

Most coding projects save versions with Git, and each saved snapshot of the project is a commit. A branch is a label pointing at the newest commit in one line of history. Each new commit moves only the label you are on. Merging joins two lines, usually through a new commit that records both.

Where you’ll meet it

You ask your coding agent to try a new layout for your site's homepage. It reports that it made a branch called “new-homepage” and committed the work there. You open the project folder to compare the old page with the new one, and there is only one homepage file.

What to do

Both versions share that folder, and the branch you're on decides which one the files show. Ask the agent to show what “new-homepage” changed from “main,” the starting branch that usually holds the accepted version, or to run the site on each. If you like the layout, have it merge the branch into “main.”

Easy to mix up

A commit is one saved moment in the project's history. A branch is a line of work that keeps growing, and switching to it gives you a place to add more commits.

Check yourself

Yesterday your agent started a branch called “checkout-redo” and committed three changes to it. Today you commit a price fix on “main.” Does “checkout-redo” have the price fix?

Go deeperBranches are instant in Git, and old ones get harder to merge

Version control systems had branches long before Git, often as full copies of the project. Git made them light enough to create for every small change, since creating or deleting one writes a few bytes and copies no project files.

The longer a branch lives, the further it drifts from the main line, and the more of its changes collide with someone else's at merge time. Many teams keep branches small and merge them within a day or two. When two agents need to work on two branches at once, Git's worktree command gives each branch its own folder.

Practice Build Basics

Or take the learning quiz on a mix of every set