# workflow, step by step:git checkout srcBranch # where new branch will be created fromgit branch newBranch # newBranch is created from srcBranchgit 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 22020 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
// Example for creating a new branch named myNewBranch
// git switch is specifically for branches whilegit checkout is for
// both branches and commits
git switch -c myNewBranch
// First Push
git push -u origin HEAD