![]() |
VOOZH | about |
A Git branch is a separate workspace used to make changes without affecting the main project. Once the work is complete, the changes can be merged back into the main or master branch.
Branches make it easy to:
Git branches allow you to manage different tasks or features in isolation without affecting the main project. Hereβs how it works:
Git uses different types of branches to keep things organized and allow you to work on different tasks without disturbing the main project. Here are the most common types of branches you will work with:
Below are some essential Git branching commands that everyone should learn when starting to work with Git branching:
Lists all local branches or creates a new branch when used with a name means it displays a list of all local branches or creates a new branch if a name is specified.
Creates a new branch with the specified name without switching to it, allowing you to stay on your current branch.
Switches to an existing branch in the repository, allowing you to continue working from where it was last updated.
Creates a new branch with the specified name and immediately switches to it, allowing you to start working on it right away.
A modern alternative to the checkout command, primarily used for switching branches more efficiently and intuitively.
Creates a new branch with the specified name and switches to it immediately, allowing you to start making changes right away.
git rebase main rewrites the feature branch commits so they appear as if they were created from the latest commit of main.
Before rebase
main: A --- B --- C
\
feature: D --- E
After rebase
main: A --- B --- C
\
feature: D' --- E'
Deletes the specified branch, but only if it has been fully merged into its upstream branch, ensuring no unmerged changes are lost.
Forcefully deletes the specified branch, even if it contains unmerged changes or has not been fully updated, potentially leading to data loss.