How do I create a new branch?
A branch is a copy of your project where you can try things.
The main branch (often called main) stays the same until you decide to bring your changes back.
Do this:
- Open a terminal in your project folder.
- Create a new branch. Pick a name that says what you’re doing. For example
fix-loginornew-button:
git branch fix-loginThat creates the branch. It does not switch you to it yet.
- Switch to the new branch:
git switch fix-loginNow you are on fix-login. Any commits you make here stay on this branch. Your main branch does not change.
Shortcut: create and switch in one step
git switch -c fix-loginThe -c means “create this branch and switch to it”. Same result as the two commands above.
Check which branch you’re on
git branchThe branch you’re on has a star next to it. Or run git status — it says “On branch fix-login” at the top.
When you’re done and want to bring your work back into main
Switch to main, then merge:
git switch maingit merge fix-loginNow the changes from fix-login are in main. See merge for more.