hastartes
hastartes

Reputation: 67

Renaming Remote Git Branches

I have been migrating an SVN Repo to Git recently and after pushing my changes to my GitHub account, I noticed that all the branches I migrated had an extra /origin tag in it:

$ git branch -a
master *
/remotes/origin/master
/remotes/origin/origin/branch1
/remotes/origin/origin/branch2

I have around 15 branches(which are owned by other people) like this, how would I be able to rename the branch without destroying their history?

Upvotes: 0

Views: 354

Answers (1)

Emil Kantis
Emil Kantis

Reputation: 1114

for branch b in branches: 
git checkout b
git checkout -b new_name
git push -u origin new_name
git branch -D b
git push -u origin :b

What happens is you checkout each given branch, create a new branch pointing to the same location in the commit-graph and push that branch. Afterwards you can delete the old one.

Upvotes: 2

Related Questions