All you need to do is
git checkout -b feature-1 master
git push -u origin feature-1
Git will automatically push feature-1 next time you issue git push
. It does not matter what branch you are on. When you issue the git push
command, git will push whatever branches you have explicitly pushed before to the first remote - but only the ones you have explicitly pushed to that remote. If you have more than one remote you can specify which one git push origin
or git push upstream
. If you explicitly want to push just one branch to a remote you need to git push origin branch-name
.
Tracking (what branch gets updated on the remote when you git push
) is handled more implicitly with the latest versions of git.
For open source, typically someone may have 2 remotes:
- a remote for their own fork of a projet.
- a second remote that's read only and can't be pushed to for the main repo of the project.
This is where you would want to be explicit about which repo you are referring to at certain times.