Sitemap

Git Incorrect Upstream Branch

2 min readApr 2, 2021

--

Today when I was working with a git had to face a funny situation. I made a local change and then pushed to remote but it wasn’t showing in remote properly and team is complaining that I have done something stupid.

Press enter or click to view image in full size
Photo by Simon Berger on Unsplash

As I started digging deeper into the problem, this was the first observation.

nuwan:$ git statusOn branch base-product-main-upgrade
Your branch is ahead of 'origin/base-product-main' by 5 commits.
(use "git push" to publish your local commits)

nothing to commit, working tree clean

Git status was comparing a different remote branch! checked other switching other branches they didn’t show this problem.

git remote show origin

Then I tried this and it gave me reason. Output was a long list and following is the place where we need to focus

Local branches configured for 'git pull':
base-product-main merges with remote base-product-main
base-product-main-upgrade merges with remote base-product-main

You can see base-product-main-upgrade this branch is focused in to a wrong remote branch.

Get Nuwan Zen’s stories in your inbox

Join Medium for free to get updates from this writer.

So how can we fix this?

While I was in the base-product-main-upgrade branch ran following command

git branch --set-upstream-to=origin/base-product-main-upgrade

Now my git status has changed to following output

nuwan $ git status
On branch base-product-main-upgrade
Your branch is up to date with 'origin/base-product-main-upgrade'.

So the conclusion is you can use git branch — set-upstream-to=xxx to set upstream branch.

Read My other blogs here:

--

--

Nuwan Zen
Nuwan Zen

Written by Nuwan Zen

Sometimes A software Engineer, sometimes a support engineer, sometimes a devops engineer, sometimes a cloud engineer :D That’s how the this life goes!