10

When I create a new branch, if I set "Configure upstream for push and pull" a warning appears (circled in blue in the screenshot). Why is that not recommended ? What potential problems or disadvantages does that have ?

I ran that warning through search engines and searched for it on https://git-scm.com and https://www.eclipse.org/egit/ but I found nothing, and when I click the "?" help button in that dialog nothing happens.

"Create Branch" dialog.

Also, if I wanted to follow the suggestion from that warning and "use remote branch", how do I do that ? Except of course the "Configure upstream for push and pull" checkbox, nothing that I change in that dialog causes the warning to disappear.

SantiBailors
  • 1,596
  • 3
  • 21
  • 44

3 Answers3

4

There is nothing wrong with setting another local branch as your upstream. It just means that git fetch does nothing—you already have all your own commits; git merge merges from the other branch; git rebase rebases onto the other branch; and git push attempts to fast-forward the other branch, or fails if it cannot.

The "other branch" (the upstream) is your own ordinary local branch, stored in your repository as usual. You are therefore your own upstream (and your own downstream, when viewed from the other branch). It feels a bit incestuous. :-)

It's completely not clear to me what other local branch EGit is going to set as the upstream, here. (I don't use EGit.) My guess, based on the stuff in the image, is master.

torek
  • 448,244
  • 59
  • 642
  • 775
  • Ok, at this stage I think that before I can understand this subject I need to study the difference between "upstream" and "remote", because from what I understand from your answer there are no non-local branches anywhere in this scenario, but I just know that there is also a remote branch, to which I push, which is what my colleagues can checkout through the local network. Plus it sounds like somehow two local branches exist, while I can only think of one. BTW if I wanted to follow the suggestion from that warning and "use remote branch", do you know how to do that ? – SantiBailors Nov 19 '16 at 09:35
  • 3
    Well ... Eclipse EGit might try to use different terminology from plain Git (which might be good in some ways since Git's is, well, not so good). But Git does not really have any "remote branches" at all, just (local) branches (branch names) and *remote-tracking* branches. Remote-tracking gets shortened to just "remote" sometimes (but should not be). Meanwhile, your Git talks to some other Git, which we can call "the remote", and the *other* Git also has (local) branches, so we could call those "remote branches". You can see how this might get pretty confusing, pretty fast! – torek Nov 19 '16 at 11:35
  • 2
    Generally, in plain Git, one sets a (local) branch—a name like `master` or `dev`—to also remember the name of a *remote-tracking branch* like `origin/master` or `origin/dev`. Then, any time you run a `git fetch` that calls up the other Git on origin, your Git gets a list of all of *their* Git's branches (their `master` etc), and copies stuff as needed to *your* repository, and then updates your `origin/master` etc to remember "what I saw over there". So your remote-tracking branches automatically update on `git fetch`. You then have your local `master` refer to `origin/master`, [continued] – torek Nov 19 '16 at 11:39
  • 2
    and then every `git fetch` updates `origin/master` and now your Git can tell you how your `master` compares to its memory of origin's `master` as stored in `origin/master`. (Whew!) That's how remote-tracking branches work: they're just memories of the branches on the remote (which don't have a formal name, but would logically be "remote branches", which is why we should carefully call *ours* "remote-*tracking* branches" instead). – torek Nov 19 '16 at 11:40
  • 3
    Last, once again, I do not use (and never have used) EGit, but logically, you would choose a different upstream by clicking the "Select..." button, which will bring up a list of your existing remote-tracking branches. Note that there is a problem if the remote `origin` has no branch yet: you won't *have* an `origin/MyNewBranch`, because your Git has not seen anything named `MyNewBranch` *on* origin, any time it did a fetch. In this case, in regular Git, you simply don't set *any* upstream ... *yet*. You set it later, after you have your Git tell their Git to *create* `MyNewBranch` over there. – torek Nov 19 '16 at 11:44
  • Thanks heaps for this extensive explanation. I will go through it thoroughly. After a first read I feel my confusion is already starting to clear. – SantiBailors Nov 19 '16 at 16:09
1

I suppose it is telling you that storing your code at another location on the same device is not helping you to preserve the code. Whereas pushing to GitHub or BitBucket would allow you to destroy your device and still have the code. i.e. Storing your code locally twice is not more save.

To fix this make a repo on either BitBucket (allows private repo's for free) or GitHub and push your code there.

Maarten Bicknese
  • 1,498
  • 1
  • 14
  • 27
  • Sorry, I'm not clear about this. After I create my branch in that way, I know that if I just commit changes they are stored in the local branch, but I periodically also push, or I just commit using the "Commit and Push" button instead of the "Commit" button, and I'm sure that this results in the creation and updating of a remote branch (which is not on GitHub or BitBucket but it's on a server in the local network). In fact other people can definitely checkout that branch from the remote. I thought that _not_ checking "Configure upstream for push and pull" would cause my branch to remain local. – SantiBailors Nov 18 '16 at 14:15
  • Ah. I believe this has to do with where the branch originated from. Can you create a branch on the remote, check it out, and see if it is still giving the message if you are to push new changes? – Maarten Bicknese Nov 18 '16 at 14:23
  • I actually don't know, because the only way I know to create a branch is right-click on a project (in Package Explorer) / Team / Switch to / New branch, and that shows the "Create Branch" dialog in the screenshot. There, I don't know how to specify that the destination where the branch must be created is the remote. It gets created locally and then the first time I push it gets created on the remote too. BTW the warning in subject is only given in the Create Branch dialog, not when I push. – SantiBailors Nov 18 '16 at 14:40
  • I suspect this to be the case. Basically it is a bogus message which you can safely ignore. See http://stackoverflow.com/a/2739476/2637098 for more information on upstream and downstream. – Maarten Bicknese Nov 18 '16 at 17:32
0

I think the better answer/explanation here is that in 99.9% of cases you SHOULD NOT check the 'Configure upstream for push and pull' in this egit dialog.

Instead you should just leave that unchecked and when you later try to push, egit will let you configure the correct upstream (at origin) for merge or rebase or whatever your preference is.

This UI is very misleading and if you do check the box (and select something from drop-down) -- which seems like a reasonable thing to do -- you are going to get something that you probably don't expect at all -- whatever you select will be the 'upstream' for your new branch (where you'll 'push' the changes) and since the actual upstream you want (same-named branch at origin) isn't available at this point, you're most likely going to end up with the messed-up configuration.

Sergey O.
  • 101
  • 4