Git Academy

Beginner · 4 min read

Branches without fear

A branch is just a sticky note on a commit. Once you get that, you'll create them all the time.

What a branch really is

A branch is a name pointing to a commit. When you commit, the name moves forward. Creating one is instant and costs nothing, so make one for every task.

Safe
$ git switch -c feature/login-page

Moving between branches

git switch changes the files in your folder to match the branch. Commit or stash your changes first, or Git will refuse to avoid losing them.

Safe
$ git switch main
$ git switch -

Cleaning up

Once merged, delete the branch: the commits stay in main. -d refuses to delete unmerged work, which is exactly what you want.

Safe
$ git branch --merged
$ git branch -d feature/login-page