1

I created a new experimental branch on my local machine:

git checkout -b feature/random-experiments

Then made some changes to a few files and committed them:

git add .
git commit -m "1st cut - added cool new experimental feature"
git push

Later, we created a user story (U-123) and then decided to rename my branch to follow our naming standard. I deleted the remote branch via stash's browser UI. Then:

git branch -m feature/U123-Add-Cool-New-Feature

Then made some changes and committed:

git add .
git commit -m "clean up & refactor"

But now, when I do a git status

$ git status
On branch feature/U123-Add-Cool-New-Feature
Your branch and 'origin/feature/random-experiments' have diverged,
and have 1 and 1 different commit each, respectively.
  (use "git pull" to merge the remote branch into yours)
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

It looks like my local branch is still pointing to the old remote branch. This is a problem because the old (remote) branch at origin : 1) had a different name 2) is no longer there as I deleted it.

What is the best way to fix this?

SGB
  • 2,118
  • 6
  • 28
  • 35

1 Answers1

0

You can reset the upstream branch for your current branch:

git branch branch_name --set-upstream-to your_new_remote/branch_name

In your case:

 git branch --unset-upstream 
 git push --set-upstream-to origin feature/U123-Add-Cool-New-Feature

Make sure you are on the right local branch:

git checkout feature/U123-Add-Cool-New-Feature

And try to push from there.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • When I tried this, I got an error message indicating that origin/feature/U123-Add-Cool-New-Feature does not exist. I ended up doing a 2 step process : 1) git branch --unset-upstream and then 2) git push --set-upstream-to origin feature/U123-Add-Cool-New-Feature. (note the space between origin and feature. – SGB Jul 22 '16 at 15:00