What you will learn
- Create, switch between and merge branches
- Open a pull request and review changes on GitHub
- Resolve a simple merge conflict
A branch is a separate line of work. The main branch should always hold working code. To build a new feature, run git switch -c add-contact-form to create and switch to a new branch. Commits made there do not affect main until you merge them. You can switch back with git switch main at any time, and list branches with git branch.
On teams, branches are merged through pull requests. You push your branch to GitHub and open a pull request asking to merge it into main. Teammates review the changes line by line, leave comments and approve. Automated checks, such as tests, often run at this stage too. Even working alone, pull requests give you a clear record of each feature and a moment to review your own work.
A merge conflict happens when two branches change the same lines differently. Git marks the conflicting section in the file with <<<<<<<, ======= and >>>>>>> lines showing both versions. You edit the file to keep the correct result, delete the markers, then stage and commit. Conflicts are normal. Pulling often and keeping branches short-lived makes them smaller and less frequent.


