git push vs git push origin <branchname>
Solution 1:
The first push should be a:
git push -u origin branchname
That would make sure:
- your local branch has a remote tracking branch of the same name referring an upstream branch in your remote repo '
origin
', - this is compliant with the default push policy '
simple
'
Any future git push will, with that default policy, only push the current branch, and only if that branch has an upstream branch with the same name.
that avoid pushing all matching branches (previous default policy), where tons of test branches were pushed even though they aren't ready to be visible on the upstream repo.
Solution 2:
First, you need to create your branch locally
git checkout -b your_branch
After that, you can work locally in your branch, when you are ready to share the branch, push it. The next command push the branch to the remote repository origin and tracks it
git push -u origin your_branch
Your Teammates/colleagues can push to your branch by doing commits and then push explicitly
... work ...
git commit
... work ...
git commit
git push origin HEAD:refs/heads/your_branch