Branch
Ветка
In Git, a branch lets you record changes without advancing another line of work. It is a name that points to a commit and moves forward as you commit on that branch.
What a branch is
Suppose you start fixing a login screen today, but the team needs to ship an unrelated change before your fix is ready. A branch lets you commit your work without adding it to main. Both lines of work share the commits they started from, but each can move forward on its own. This is a version-control branch, not a path through an if statement.
What Git actually stores
A branch is a named reference to a commit. Creating fix/login-label from main initially gives two names to the same commit; it does not duplicate the project or create a commit. Git finds the history behind either name by following parent links from the commit that name points to.
When you switch to a local branch, HEAD normally refers to that branch. A new commit advances the current branch reference and leaves the other branch references alone. If you check out a specific commit rather than a branch, HEAD can point directly to that commit. This is called detached HEAD: you can still commit, but no branch reference advances with you.
Example: create a branch and share it
Start from the local version of main you intend to build on, then make and publish the change:
git switch main
git switch -c fix/login-label
# Edit the label in login.html
git add login.html
git commit -m "Fix login form label"
git push -u origin fix/login-label
git switch -c creates the branch and switches to it. The push publishes it to origin, and -u associates the local branch with its remote counterpart for future pulls and pushes. A pull request targeting main gives teammates a place to review the change before it lands. A branch does not need to be pushed if it is only for local work.
Typical uses and common mix-ups
Teams often use short-lived branches for features and bug fixes. A longer-lived release branch can receive patches for a supported version while new development continues on main. main is a conventional name, not a special kind of Git branch. Hosting rules can protect it by requiring reviews or passing checks before changes land.
A local branch and a remote-tracking reference are not the same thing. For example, origin/main records where your repository last learned the remote branch was. Running git fetch origin can update origin/main without moving your local main. Also, creating a branch does not save your uncommitted edits: those edits can follow you when you switch branches if Git can carry them over safely.
How it comes up in interviews
Interviewers often draw a commit graph and ask what moves when you merge. If the current branch tip is an ancestor of the incoming tip, Git can do a fast-forward: it moves the current branch reference without creating a merge commit. With diverged history, a standard merge creates a commit with both tips as parents after any conflicts are resolved. The incoming branch does not move in either case.