How to push a new local git branch to a remote repository

First create a new git branch with git checkout -b [new-branch-name]. Then push it with git push -u origin [new-branch-name]. The -b option in git checkout is a shortcut for two commands. It’s the same as:

git branch [new-branch-name] 
git checkout [new-branch-name]

The -u option in git push is a shorter version of --set-upstream which allows git to track the upstream branch. This removes the need to specify the branch name in further git commands.

Example: Push new git branch to remote repository

Source: https://www.freecodecamp.org/forum/t/push-a-new-local-branch-to-a-remote-git-repository-and-track-it-too/13222

Published 14 Dec 2019

Remote Developer | Vegan | Pro Wrestling geek | Gamer | Scared of his kids becoming teenagers
Remote Ren on Twitter