Branches
Branching & Merging
Preview
Branches
A branch is a copy of the project history you can work on independently. The main branch stays safe while you experiment.
Branch commands
git branch # list branches\ngit branch feature-nav # create\ngit switch feature-nav # switch to it\ngit switch -c feature-nav # create + switch\n\ngit branch -d feature-nav # delete merged branchA typical session
git switch -c add-dark-mode\n# ... make changes ...\ngit add .\ngit commit -m "Add dark mode"\ngit switch main\ngit merge add-dark-modeThe naming convention
feature/… # new features\nfix/… # bug fixes\nchore/… # maintenance\nhotfix/… # urgent production fixesWhy branch
- Feature work never breaks main
- Two people work in parallel
- Experiments can be discarded safely
Tip: Make main always work. Everything risky or unfinished lives on a branch.
This is a free preview lesson
Enroll in the Git & GitHub for Beginners to unlock every lesson, lesson PDF guides, quizzes and your certificate - and start creating your own pieces today.