且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

git删除并重新创建分支

更新时间:2023-11-17 14:33:52

我必须删除跟踪分支

  git branch -d -r origin / develop 


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 ?

i had to delete the tracking branch as well

git branch -d -r origin/develop