Branches and Merging

Keep main as the base for your project. Create a branch when you want to develop a change and bring it into main after checking it.

On this page

Create a branch and commit a change

A branch is a named pointer to a commit. When you commit on add-usage, Git advances that branch while main stays at its previous commit. Start from main in project-notes and append a short usage section.

git switch -c add-usage
printf '\n## Usage\nRead the notes before starting.\n' >> README.md
git add README.md
git commit -m "Add usage notes"
git branch

Merge a branch into main

Switch to the branch that should receive the changes, then name the branch to merge from. If main has no new commits since the branch was created, this example can fast-forward. Git moves main to the commit already on add-usage.

git switch main
git merge add-usage
git log --oneline --graph --all

Official references