# workflow, step by step:
git checkout srcBranch # where new branch will be created from
git branch newBranch # newBranch is created from srcBranch
git checkout newBranch # switch from srcBranch to newBranch
# in a single line:
git checkout -b newBranch srcBranch
git checkout -b newBranch # srcBranch is optional if already checked out
$ git checkout -b [your_branch_name]
# Switched to a new branch [your_branch_name]
# This is shorthand for:
$ git branch [your_branch_name]
$ git checkout [your_branch_name]
branchShell/Bash By Scriper on Sep 2 2020 Comment
// Example for creating a new branch named myNewBranch
git checkout -b myNewBranch
// First Push
git push --set-upstream origin myNewBranch
# create and switch to the new branch
git checkout -b <Name_of_your_branch>
# example
git checkout -b testBranch1
# if you check your current branch it will show you testBranch1
- git branch xyz ==>
it creates new branch named 'xyz' but still keep being on master branch
- git checkout xyz ==>
it will change your branch to the develop branch
- git checkout -b xyz ==>
it creates also a branch named xyz and switches to it automatically
git checkout -b [yourbranchname]
git commit
Note: In Git version 2.23, a new command called git switch was introduced to
eventually replace git checkout
// Example for creating a new branch named myNewBranch
// git switch is specifically for branches while git checkout is for
// both branches and commits
git switch -c myNewBranch
// First Push
git push -u origin HEAD