9

The scenario is that I have no repos on the remote server, just an account. Then, I run locally the following commands, where x is the user name and y is the project name that only exists on my local system.

git init  
git remote add buckety https://x@bitbucket.org/x/y.git  
git add .  
git commit --message "Here we go..."  
git push buckety

Now I get the error urging me to set up the remote upstream. I can do that (either --set-upstream or -u) but according to my googlearching, it's been deprecated. (Actually weird that the suggestion in the console mentions it still.)

I want to do it the proper way and I've goolearched both --track and --set-upstream-to. However, there's no example for my particular scenario on Git as far I could see and the operations I've tested failed with errors.

How should I create the remote branch without retracting to using the deprecated option? I might want to create a tracking branch on remote so that:

  1. the local branch A corresponds to the remote branch A, but also
  2. the local branch A corresponds to the remote branch B.

Preferably, I'd like to configure it prior to the push but I'm not sure how. I can't use checkout because the branch doesn't exist yet. I can't use set-upstream-to for the same reason.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438

3 Answers3

10

The right command is:

git push -u origin master

Then the next git push will be a simple: git push.

See "Why do I need to explicitly push a new branch?"

Since Git 1.8, --set-upstream is called --set-upstream-to

You can setup a remote tracking branch in advance with:

git branch -u origin/master master 

(Then your first git push would have been a simple git push)

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • So the *-u* **was** a short for *--set-upstream* before and now it's short for *--set-upstream-to*? Or should I understand that the deprecation isn't effective for the initial push (and that it's appropriate to use it) but that it's effective for subsequent work (and one shouldn't use it later on)? What exactly is the difference between *--set-upstream* and *--set-upstream-to* on the initial push? Nothing, right? – Konrad Viltersten Nov 13 '16 at 16:03
  • @KonradViltersten -u is still valid and now is indeed short for `--set-upstream-to`. `--set-upstream` is deprecated. – VonC Nov 13 '16 at 16:03
  • Awesome. But I'm a verbose person so I happen to use the *--set-upstream* withing the suffix. Revising the stuff on the server, I see no difference. What should I notice, please (if I wasn't so ignorant of the nuances)? – Konrad Viltersten Nov 13 '16 at 16:05
  • @KonradViltersten this is a local setting, for your local repo to know where to push (read http://stackoverflow.com/a/17096880/6309). You can see it when doing a `branch -vv master` – VonC Nov 13 '16 at 16:10
  • Godlike! I'd give you +1 but I already did because I got excited. :) – Konrad Viltersten Nov 13 '16 at 16:11
  • @KonradViltersten: the main difference between `--set-upstream` and `--set-upstream-to` lies in the *treatment of additional arguments*. Running `git branch newbr --set-upstream br2` *creates* branch `newbr` with its upstream set to `br2`; running `git branch oldbr --set-upstream-to br2` sets the upstream of *existing* branch `oldbr` to `br2`. The details get more fiddly when you're *not* creating a new branch and use `--set-upstream`. – torek Nov 13 '16 at 19:31
2

For me pushing an existing local branch to a branch that doesn't (yet) exist on the server is:

git push --set-upstream origin LocalBranchThatDoesntExistOnServer
Owl
  • 1,446
  • 14
  • 20
0

That is how i push to gerrit instance without adding remote

git push http://localhost:8080/scm *:*
fatal: remote error: Git repository not found

But the project must exist already

Filip Stefanov
  • 800
  • 3
  • 10
  • 18
  • Oh, I start to see the issue. I **must** create the repo by *git init* but executed **on the server**. Then, I can do the rest. Of course, BitBucket won't let me access the command line but I can create the repo from the GUI. I prefer to do stuff from TUIs. It always feels like GUI will make me lazy and dumb(er)... Also, working with text interface makes you look cool, like the kid from 80's movie *War Games*. – Konrad Viltersten Nov 13 '16 at 16:08
  • @KonradViltersten you would not be able to do a git init on the server side, since the server is BitBucket (bitbucket.org). You must have created an empty repo there (with the BitBucket web GUI) first. – VonC Nov 13 '16 at 16:11
  • I suggest you to follow this tutorial: – Filip Stefanov Nov 13 '16 at 16:11
  • https://confluence.atlassian.com/bitbucket/create-a-git-repository-759857290.html – Filip Stefanov Nov 13 '16 at 16:11