git delete and recreate branch
Asked Answered
V

2

20

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 ?

Vacationist answered 7/8, 2012 at 11:5 Comment(2)
What is git diff develop origin/develop telling you after you try to reset the branch?Laban
nothing, no line output .. but git pull gives still the rejected message. Mhh HEAD is set to a wrong commit so .. i thought it was the right one because of the message, but the hash tag is wrong.Vacationist
V
19

i had to delete the tracking branch as well

git branch -d -r origin/develop
Vacationist answered 27/8, 2012 at 17:34 Comment(1)
I tried this and it worked locally, however I also needed to login to bitbucket.org and delete the branch from there to be able to recreate the branch and push the new version of the branch successfully.Charlinecharlock
F
9

You can not pull because it's an other branch now.

Maybe you should start from scratch and fetch the remote develop branch as a new local branch!

git checkout -b new_develop --track origin/develop

After doing this, you can merge or change between branches on your local machine. Compare directory trees and other files.

If you are done editing, just remove your local develop branch, and rename the new_develop to develop.

Fennessy answered 7/8, 2012 at 11:10 Comment(5)
there is nothing i want to merge, i just want to have the new develop branch. If i checkout with new_develop and delete the old develop i still get the rejected message, even if just delete develop and don't check it out again, i get the rejected messageVacationist
when you check it out to the new_develop local branch with the track option you need to stay on this branch and pull the origin. Hm. You can check the tracked remote branches at .git/config. You say something like you couldn't simple clone the origin repo, could you?Fennessy
i could clone it, but it's an eclipse project and always deleting the repository when someone recreates the develop branch doesn't seem like a good solution for the future. [edit: oh and i can pull the new branch, but i still get the rejected message for the old develop branch it's like independent an leftover, i don't know)Vacationist
I wasn't be able to use git repositories properly from eclipse : eGit had some problems. The real git "workflow" is well managed via command line. I use it via command line with git completion ( github.com/ypetya/dotfiles/blob/master/.git-completion )Fennessy
jeah, egit has the problem that the checked out repository has to be outside of the workspace. I just deleted it for now. For next time i got the advice to delete my local develop branch and my local remote/develop branch. When i'll have to do it next time i report back ;). And i use the command line as well.Vacationist

© 2022 - 2024 — McMap. All rights reserved.