Branching is used to develop features isolated from others.
By default, git creates a master branch. This branch is considered the root and should ultimately contain all code changes.
The idea is that you want to create a new feature but you don't want to check directly into the master branch. Or let's say you are working on a prototype and not really sure if it's going to work out.
Creating a new branch
To create a new branch:
git branch MyNewBranch
To switch to that branch:
git checkout MyNewBranch
Or to create a new branch and switch to it:
git checkout -b MyNewBranch
To see what branches are local and remotely:
git branch -a
* master remotes/origin/HEAD -> origin/master remotes/origin/master
The * indicates the current branch. The remotes/origin/master is the remote copy of your local branch.
Deleting a local branch
To delete the branch locally:
git branch -d MyNewBranch
Deleting a remote branch
To delete the branch on the remote:
git push origin :MyNewBranch
Merging your branch
After you've completed your feature work, you'll want to merge your branch back into master.
NOTE: This is assuming all your changes are committed.
|Copyright 1999-2021 by Cstructor LLC. All rights Reserved.|