Branches
15 min. | Beginner
View Current Branch Location
Lists all branches in your local repo and highlights the one you’re currently on with an asterisk (*). Useful for making sure you’re working in the right place before committing or merging.
git branchCreate a New Branch
Branches let you safely experiment with new ideas. This command creates a new branch and switches you to it.
git checkout -b branch-nameBranches are local by default — others won’t see your new branch unless you push it to GitHub.
git push origin branch-nameThis uploads your branch so others can collaborate.
Switch to Main and Merge
Once your feature is ready, switch back to the main branch and merge your changes in. This brings your work into the main codebase.
git checkout main
git merge branch-nameIf both branches edited the same part of a file, Git can’t automatically merge. You’ll need to manually fix the conflict, then commit the result.
Delete the Feature Branch
After merging, you can delete the branch to keep your workspace clean. Don’t worry — the changes are still in main.
git branch -d branch-name