2

I've used the script provided by GitHub to change author info of a GIT repository. While running the script there were some errors which resulted in each branch being duplicated as the origin. I need to keep the origin branches and delete the others. I can't switch to the origin branches because it throws an error:

fatal: A branch named 'Development' already exists.

How can I restore my repository to only keep the origin branches? My branches look like this in sourcetree:

sourcetree

3
  • 1
    Delete the local ‘Development’ branch with git branch -D Development and then you should be able to checkout origin/Development. Commented May 2, 2019 at 21:26
  • 1
    The script to change authors / committers does duplicate the commits (and hence the branches). That's how it changes things. You can't actually change any commit; you have to make a new, different, new-and-improved commit. This affects every subsequent commit. What you end up with is typically, effectively, a new, incompatible repository; that seems to be the case here, for instance.
    – torek
    Commented May 2, 2019 at 21:31
  • This happened to me when I did 'git checkout <branch>' in which <branch> was not a local branch. Even though I didn't use the -b option it seemed to go ahead and create a duff branch anyway. Then when I tried to actually track the remote branch with ' git checkout --track <branch>' it complained that the branch already existed. I was able to delete it using the command that Cristian above gave and then re-checkit out correctly. I wish gitlab didn't do this
    – Motorhead
    Commented Mar 25 at 22:33

1 Answer 1

3

You could reset your Development branch to the origin one:

git checkout Development
git reset --hard origin/Development

That should be enough.

Not the answer you're looking for? Browse other questions tagged or ask your own question.