This tutorial will help you will simple steps to how to create Git branches and switching between branches.
-
Create New Branch:
Use -b switch to create new branch with ‘git checkout’ command’. As per below command will create new branch and switch to new branch automatically.
$ git checkout -b stage1 Switched to a new branch 'stage1'
-
List Branches:
This will list all branches used in current working git repository. The branch name start with “ * ” shows your current active branch, in which you are working on.
$ git branch master *
stage1 -
Switch to Other Branch:
Use the following command to switch to any other branch. Change ‘master‘ with your new branch name in below command to switch.
$ git checkout master Switched to branch 'master' Your branch is up-to-date with 'origin/master'.
Now again list branches, you will get that master will be your active branch.
$ git branch *
master stage1 -
Push New Branch:
Now push your newly created branch ‘stage1‘ to remote git repository. To push new branch first switch to that branch.
$ git checkout stage1 Switched to branch 'stage1'
Now use following command to push your branch ‘stage1’ to remote git repository.
$ git push origin stage1 Username for 'https://github.com': your_git_user_name Password for 'https://your_git_user_name@github.com': Total 0 (delta 0), reused 0 (delta 0) To https://github.com/tecadmin/firstrepo.git * [new branch] stage1 -> stage1
Comments
Post a Comment