Branching in GitHub allows developers to work on different features, fixes, or experiments independently without affecting the main codebase.
A branch can be created locally using Git or directly from GitHub. Once work is complete, branches are merged back using pull requests.
// Create and switch to a new branch
git checkout -b feature-login
// Push local branch to remote repository
git push -u origin feature-login
// Switch to an existing branch
git checkout main
// List local and remote branches
git branch -a
// Delete branch after merge
git branch -d feature-login
Each command updates Git’s internal references. Branch creation does not duplicate files, it only creates pointers.
Imagine branches as parallel timelines where changes happen independently and later merge back.