Understanding Branches
A branch in Git is an independent line of development. The default branch is usually called `main` (or `master` in older repos). Branches let you work on new features or fixes without affecting the main codebase.
Branches in Git are lightweight and fast to create because they're just pointers to a specific commit, not full copies of the project. This encourages frequent branching for experiments and features.
git branch
git branch -aWhy use branches?
Branches isolate work in progress. You can experiment, build a feature, or fix a bug on a branch, and only merge it into main once it's tested and ready.
Listing branches
Run `git branch` to see all local branches, with an asterisk marking the branch you're currently on. Use `git branch -a` to also see remote branches.
git branch* main
feature-loginLists local branches; the asterisk shows main is the currently checked-out branch.
git branch -a* main
feature-login
remotes/origin/mainShows both local branches and remote-tracking branches.
Key points
- A branch is an independent line of development.
- The default branch is usually called main.
- Branches are lightweight pointers to commits, not full copies.
- git branch lists existing branches; the asterisk shows the current one.
