5

After doing

git init git remote add origin <some_origin> 

You can's simply commit and push, since it says

fatal: The current branch master has no upstream branch. To push the current branch and set the remote as upstream, use git push --set-upstream origin master To have this happen automatically for branches without a tracking upstream, see 'push.autoSetupRemote' in 'git help config'. 

Is there a way of setting the upstream branch without using git push?

Eg. something like:

git upstream origin master 
11
  • 3
    git branch --set-upstream-to=some-branch Commented Feb 1, 2023 at 8:10
  • 1
    "You can't simply commit and push... without using git push" -> Isn't there a contradiction in your question? In your first scenario, you do push. Commented Feb 1, 2023 at 8:26
  • eftshoft0 gave the answer : there is an option in git branch for that. There is a sanity check, which only allows to set it to a known branch, so you technically need to run git fetch origin at least once if you want to set git branch -u origin/that_branch Commented Feb 1, 2023 at 8:39
  • 2
    But that's exactly what I'm asking: how do I do that without git push -u. Commented Feb 1, 2023 at 9:22
  • 1
    The branch needs to be known to git... if the branch does not exist...... Anyway, if you feel like you are in the hacking mode, edit .git/config and set the upstream by providing remote and a merge setting for the local branch. So, a line with remote = some-remote and another with merge = refs/heads/some-branch. And you are on your own. :-) Commented Feb 1, 2023 at 9:58

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.