Git Incorrect Upstream Branch
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.
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 originThen 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-mainYou 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-upgradeNow 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:






