git-create-branch
Create a new Git branch
TLDR
Create a local branch
Create a branch locally and on origin
Create a branch locally and on upstream (through forks)
SYNOPSIS
git branch [options] new_branch_name [start_point]
PARAMETERS
new_branch_name
The desired name for the new branch. Branch names should be descriptive and typically don't contain spaces or certain special characters (e.g., '/', '~', '^', ':', '?', '*').
[start_point]
An optional argument specifying the commit ID, tag, or existing branch from which the new branch will originate. If omitted, the new branch will point to the current HEAD (the commit you are currently checked out on).
--track, -t
Sets up 'tracking' information. This means the new local branch will automatically track an upstream branch (e.g., a remote branch) of the same name if one exists. This is commonly used when creating a local branch from a remote one, like git branch --track my_feature origin/my_feature.
--no-track
Overrides the default behavior of setting up tracking if it would otherwise be implied (e.g., when creating a local branch with the same name as a remote one from a remote tracking branch).
--force, -f
If a branch with new_branch_name already exists, Git will forcefully move it to the start_point, discarding its previous history. Use with extreme caution, as this can lead to loss of work if the existing branch contained unmerged commits.
DESCRIPTION
The git branch command is fundamental to Git's branching model, allowing users to create, list, rename, and delete branches. In Git, a branch is simply a lightweight, movable pointer to one of the commits in your repository's history. When you create a new branch, Git creates a new pointer at the current commit you're on, allowing you to diverge your work, develop new features, or fix bugs without affecting the main codebase.
While the query references "git-create-branch," it's important to note that this is not a standard Git command. The correct and widely used command for creating branches is git branch. It's possible that "git-create-branch" might be a custom alias, a wrapper script, or a misunderstanding of the standard command's usage. This analysis focuses on the standard git branch command and its branch creation capabilities.
CAVEATS
The command 'git-create-branch' is not a standard Git command. The information provided here pertains to the standard 'git branch' command.
Creating a branch only creates a pointer; it does not automatically switch your working directory to that branch. To move to the newly created branch, you must explicitly use git checkout new_branch_name or git switch new_branch_name.
Branch names cannot contain control characters, space, tilde (~), caret (^), colon (:), question mark (?), asterisk (*), or open square bracket ([). It's also best practice to avoid backslashes (\) and leading/trailing slashes in branch names.
GIT'S BRANCHING PHILOSOPHY
Unlike traditional version control systems where branches might be heavy, isolated copies of the codebase, Git branches are incredibly lightweight pointers. This design encourages developers to create branches frequently for small, isolated tasks, promoting a highly flexible and non-linear development workflow.
THE `GIT-<COMMAND>` PATTERN
Git commands often follow a pattern where git looks for an executable named git-
HISTORY
Git was created by Linus Torvalds in 2005 for Linux kernel development, primarily to handle distributed development efficiently. Its core strength lies in its robust and cheap branching model, which was a significant departure from older version control systems. The git branch command has been a fundamental part of Git since its inception, embodying the lightweight pointer concept that makes branching and merging so flexible and commonplace in Git workflows.
SEE ALSO
git checkout(1), git switch(1), git merge(1), git push(1), git log(1)