Lesson

GitHub Branch

10 min reading
Free Course

GitHub Branch: Managing Shared Branches Online

A branch on GitHub stores a shared line of commits on the remote server so multiple developers can review, test, and merge work together. Every local branch you push becomes a remote branch visible to your team under the repository's Branches page.

Creating and Switching Branches in the GitHub UI

To create a branch directly on GitHub:

  1. Open your repository's Code tab and click the branch dropdown (usually showing main).
  2. Type a descriptive name such as feature/header-nav.
  3. Click Create branch: feature/header-nav from 'main'.

GitHub creates the new branch immediately from the current tip of main, letting you or a teammate edit files or pull that branch locally.

Remote-Tracking Branches (origin/*)

Locally, Git keeps read-only snapshots of remote branches prefixed with origin/, such as origin/main and origin/feature/header-nav. List both local and remote-tracking branches from your terminal:

git fetch origin
git branch -a

To clean up stale local origin/* references after branches are merged and deleted on GitHub, run:

git fetch --prune

Protecting main with Branch Protection Rules

In Settings > Branches, add a branch protection rule for main on team repositories:

  • Require a pull request and at least one approval before merging.
  • Require CI status checks to pass before a PR can merge.
  • Block direct force pushes and accidental deletion of main.

Common Branch Management Mistakes

Leaving dozens of old merged feature branches sitting on GitHub clutters the branch picker. Enable Automatically delete head branches in GitHub repository settings so merged PR branches clean up automatically.

Frequently Asked Questions

If I create a branch on GitHub, does it appear on my laptop automatically?

No. Run git fetch origin first so your local Git downloads the new remote branch pointer, then check it out with git switch <branch-name>.

What happens if I delete a branch on GitHub before merging it?

Unmerged commits on that branch become orphaned, though GitHub temporarily keeps them in recent activity so you can click Restore branch right away if deleted by mistake.

Should main ever be deleted on GitHub?

No. main serves as the default production or integration branch for clones, pull requests, and documentation links.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol
Git Topic Hub

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum