Branches are Git's mechanism for parallel development, allowing multiple lines of work to coexist without interfering. The command git branch <branch-name> creates a new branch that points to the current commit, while git checkout -b <branch-name> both creates a branch and immediately switches to it. To move between existing branches, git checkout <branch> updates the working directory to reflect the selected branch's state. Listing branches is done with git branch for local branches, git branch -r for remote ones, and git branch -a for everything; the active branch is always marked with an asterisk.
Once work in a branch is complete, it must be integrated back into another branch, typically the main line of development. The command git merge <branch> incorporates the named branch's changes into the current one. When the target branch has not diverged, Git performs a fast-forward merge by simply moving the branch pointer forward, producing no additional commit. The --no-ff option forces a merge commit even in this situation, preserving evidence that a branching workflow took place. To remove a branch that is no longer needed, git branch -d <branch> safely deletes it if its changes have already been merged; -D forces deletion of unmerged branches.
An alternative to merging is git rebase <branch>, which replays the current branch's commits on top of another branch to create a linear history. Because rebasing rewrites commit hashes, it should be avoided on branches that others have already pulled or cloned. Compared with merge, which preserves the exact branching topology using a merge commit, rebase produces a cleaner timeline but alters commit identifiers. When developers need to set aside incomplete work temporarily, git stash saves uncommitted changes and reverts the working directory to match the last commit; the work can later be restored with git stash pop. Stashes can be reviewed with git stash list and applied selectively using indexed entries like stash@{0}, while git stash drop <stash> permanently removes an entry.