1

I have upstream and origin. I'm currently not using origin, and updating everything to upstream only. The only branches locally or on either remote are main.

I did git fetch upstream followed by git reset --hard upstream/main. That had the desired effect of making my local the same as the last commit from the upstream remote.

But now when I commit I'm getting:

On branch main
Your branch is ahead of 'origin/main' by 7 commits.
  (use "git push" to publish your local commits)

I don't want to use origin at all and previously I wasn't getting this message when committing.

How can I solve this? I've tied my repos in knots before by hacking at little things like this so want to do it right.

DanielSon
  • 1,415
  • 4
  • 27
  • 40

1 Answers1

1

A local branch can be configured to track a remote branch. (What you call "the default.") This puts them in an automatic relationship for push, pull, and news about who is ahead.

Your main is tracking origin/main and it always was. Your git reset --hard upstream/main didn't change that, but it did put your main out of phase with origin/main, so now you're getting automatic news about the difference.

If you don't want automatic news about origin/main, set your main to track upstream/main instead:

git branch -u upstream/main

Or just turn off the tracking entirely:

git branch --unset-upstream

If you do that, you will have to be more verbose when you push or pull, but you will be in less danger of the wrong thing happening automatically.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • 1
    See https://stackoverflow.com/a/37770744/341994 for a good explanation. – matt Sep 01 '21 at 12:15
  • In my opinion you should take the second option and unset the upstream completely, because you have put yourself into a complex situation (two remotes) with no clear understanding of what you're doing. The less automatic behavior, the better. – matt Sep 01 '21 at 12:30