Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git delete and recreate branch

Tags:

git

Abstract: To reproduce the error

  • create a branch and check it out
  • let someone else delete it and create a new branch with the same name
  • now do git branch -D <branch> and git checkout -b <branch> --track origin/<branch>
  • on a git pull you get ! [rejected] <branch> -> origin/<branch> (non-fast-forward)

to fix it, you have to delete the remote tracking information with git branch -d -r origin/<branch> as well


OLD: Someone deleted the develop branch and created it to remove all feature branches and have the master as base again. Then he added some of the feature branches but not some others that made problems.

I did a git branch -D develop and git checkout -b develop --track origin/develop.

When i now try git pull i get a ! [rejected] develop -> origin/develop (non-fast-forward)

a git remote show origin shows

Local refs configured for 'git push': 
develop       pushes to develop     (local out of date)

i can now do a git fetch origin develop and git merge FETCH_HEAD but then i have some conflicts and he wants to push a lot of things to develop. (maybe the old branch commits?) And with a git reset --hard i'm back where the git pull shows the rejected message ..

How do i checkout the recreated branch best?

EDIT: even when i do git branch -D develop i get with git pull ! [rejected] develop -> origin/develop (non-fast-forward) and git remote show origin said everything (up to date)

EDIT: i didn't recognized it at first, because the commit message was the same, but after a reset the HEAD is on a sha that the remote does not have, so still on the "old" branch ?

like image 702
webstrap Avatar asked Aug 07 '12 11:08

webstrap


1 Answers

i had to delete the tracking branch as well

git branch -d -r origin/develop
like image 181
webstrap Avatar answered Oct 07 '22 00:10

webstrap