Branching and Merging
A branch is an independent line of development. The default branch is usually called main.
Creating and switching branches
git branch feature-login # create a branch
git switch feature-login # switch to it
# or do both in one step:
git switch -c feature-login
Older tutorials use git checkout -b feature-login, it does the same thing as git switch -c.
Merging
Once your branch is ready, merge it back into main:
git switch main
git merge feature-login
Merge conflicts
If the same lines were changed on both branches, Git can't automatically decide which version to keep, that's a merge conflict. Git marks the conflicting lines directly in the file:
<<<<<<< HEAD
const greeting = "Hello!";
=======
const greeting = "Hi there!";
>>>>>>> feature-login
Edit the file to keep the version you want, remove the <<<<<<</=======/>>>>>>> markers, then stage and commit as usual.
WARNING
Always pull the latest changes before starting new work, resolving a conflict is much easier when it's small.