Method 1: Create branch from main, then switch
git branch <new-branch-name> main
git checkout <new-branch-name>
Method 2: Create and switch in one command
git checkout -b <new-branch-name> main
Method 3: Using newer git switch command
git switch -c <new-branch-name> main
Examples:
# Create a new feature branch from main
git checkout -b feature-user-authentication main
# Create a bug fix branch from main
git switch -c fix-login-issue main
# Create a hotfix branch from main
git checkout -b hotfix-critical-bug main
After created new brach you can't push/pull your code let's try here first:
git push --set-upstream origin <branch-name-you-created>
Top comments (0)