-1

I cloned a remote branch to my local, and checked out to a new branch with the command:

git checkout -b branchname

and then I tried to push this new branch to remote and to setup upstream, but I incorrectly forgot to specify the branchname:

git push -u origin

what happens in this case? Did I cover other people's work on the remote branches?

Thanks in advance.

  • What was the output? I'm pretty sure Git won't let you overwrite remote branches without forcing. – evolutionxbox Nov 01 '18 at 22:43
  • Possible duplicate of [Default behavior of "git push" without a branch specified](https://stackoverflow.com/questions/948354/default-behavior-of-git-push-without-a-branch-specified) – phd Nov 02 '18 at 22:27
  • https://stackoverflow.com/search?q=%5Bgit%5D+push+default – phd Nov 02 '18 at 22:27

2 Answers2

0

By default, git checkout -b does not set up a tracking branch,

so git push -u origin will fail and do nothing:

$ git push -u origin
fatal: The current branch cast has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin branchname

To have this happen automatically for branches without a tracking
upstream, see 'push.autoSetupRemote' in 'git help config'.
ChrisB
  • 1,540
  • 6
  • 20
-1

If you want to push new local branch to origin without specifying new branch name exclusively.

 git push origin $(git branch --show-current)

Explanation :

git branch --show-current shows the current branch name as string.

git push origin takes this newly created current branch name as branch name argument and pushes the current committed changes

For behavior of

git push -u origin

Check this answer as mentioned in the commment.