A branch represents an independent line of development. Branches serve as an abstraction for the edit/stage/commit processes. You can think of them as a way to request a brand new working directory, staging area, and project history. New commits are recorded in the history of the current branch, which results in a fork in the history of the project.
The git branch
command lets you create, list, rename, and delete branches. It doesn’t let you switch between branches or put a forked history back together again. For this reason, the git branch
is tightly integrated with the git checkout
and git merge
commands.
Git Flow: Pros and Cons (Branch)
As with other Git branch strategies, GitHub flow has some highlights and downfalls.
How to create branches:
git checkout –b <branch name>
Git push –set-upstream origin <branch name>
Note: We can also use the git checkout command to toggle back and forth between our two branches.
Checkout
You can use git checkout on the command line to create a new branch, change your current working branch to a different branch, or even switch to a different version of a file from a different branch with git checkout [branch name] [path to file]. The "checkout" action updates all or part of the working tree with a tree object or blob from the object database and updates the index and HEAD if the whole working tree is pointing to a new branch.
Cherry-picking
To choose a subset of changes from a series of changes (typically commits) and record them as a new series of changes on top of a different codebase. In Git, this is performed by the git cherry-pick command to extract the change introduced by an existing commit on another branch and to record it based on the tip of the current branch as a new commit. For more information, see git-cherry-pick in the Git documentation
Note: git-cherry-pick: Apply the changes introduced by some existing commits