Git: Branches

When you commit a file to Git, you are committing it into the current branch.

Git allows you to work simultaneously on multiple, separate branches, different lines of development which represent forks of the main branch.

Git is very flexible: you can have an indefinite number of branches active at the same time, and they can be developed independently until you want to merge one of them into another.

Git by default creates a branch called main. It’s not special in any way other than it’s the one created initially.

You can create a new branch called develop by typing

git checkout -b develop

The git branch command lists the branches that the repository has.

When creating the new branch, that branch points to the latest commit made on the current branch. If you switch to it (using git checkout develop) and run git log, you’ll see the same log as the branch that you were previously.

Lessons in this unit:

0: Introduction
1: Installing Git
2: Initialize a repository
3: Commit changes
4: ▶︎ Branches
5: Push and pull
6: Working with a remote
7: Solving conflicts
8: .gitignore
Are you intimidated by Git? Can’t figure out merge vs rebase? Are you afraid of screwing up something any time you have to do something in Git? Do you rely on ChatGPT or random people’s answer on StackOverflow to fix your problems? Your coworkers are tired of explaining Git to you all the time? Git is something we all need to use, but few of us really master it. I created this course to improve your Git (and GitHub) knowledge at a radical level. Launching May 21, 2024. Join the waiting list!