Git doesn’t let you create a branch directly on a remote server — you always create it locally first, then push it up. Once you know the right push command, the whole process only takes a couple of steps.
Why You Can’t Create a Remote Branch Directly
Git doesn’t allow creating a branch directly on a remote. Instead, you create a local branch first and then push it to publish it on the remote. Some Git hosting platforms are an exception to this in practice — GitHub, GitLab, and Bitbucket all offer the option to create a branch directly through their web interface — but at the command-line level, the local-branch-then-push workflow is how it actually works under the hood.
Step 1: Create and Switch to a Local Branch
The fastest way to do this in one step is with git switch -c:
git switch -c new-branch
This creates a new branch based on your current branch and switches to it immediately. If you’re on an older Git version, the equivalent classic command still works:
git checkout -b new-branch
Both commands do the same thing — they create a new branch and switch to it in a single step.
Step 2: Make Your Changes and Commit
Before pushing, you’ll typically make your changes and commit them locally:
git add --all
git commit -m "Added a new feature."
Step 3: Push the Branch to the Remote
This is the step that actually creates the branch on the remote server:
git push -u origin new-branch
This command creates a new branch named new-branch in the remote repository at origin and associates it with the new-branch branch in your local repository. That association is what people mean by “tracking” or “upstream” — it establishes a link between your local branch and the corresponding branch on the remote, so future pushes and pulls don’t need the remote or branch name specified explicitly.
Once that tracking relationship exists, later pushes only need:
git push
From that point on, you can run plain git push and git pull without specifying the remote or branch name — Git looks up the tracking relationship automatically.
Verifying the Remote Branch Was Created
To confirm the push worked, list your remote-tracking branches:
git branch -a
This shows your local branches alongside remote references, including something like remotes/origin/new-branch, confirming the branch now exists on the remote.
Common Mistakes to Avoid
- Forgetting the
-u (or --set-upstream) flag on the first push — without it, Git pushes the branch but doesn’t set up tracking, so you’ll need to specify the remote and branch name manually on every future push.
- Trying to push before setting up a remote connection at all — if you haven’t added a remote yet, run
git remote add <url> first and confirm it with git remote -v.
- Assuming a local branch automatically has a remote counterpart — Git does not automatically create a branch with a similar name on the remote repository just because you created one locally.
Join The Discussion
How do you usually create and publish branches in your own workflow — straight from the command line, through a GUI client, or via your Git host’s web interface? Share any habits you’ve picked up around naming conventions, tracking setup, or cleaning up stale remote branches, and if you’ve ever gotten tripped up by forgetting the upstream flag, that’s a good story to hear too.