2

I'm working on a project that has been messed up a little bit on Github. Currently the master branch is an old not used branch (its written in angular with mdl instead of angular material). the actual project is now in another branch.

Current status 2 Branches :

  • master (which is not used, but shouldnt be deleted)
  • protoype (which we want to rename to master, without loosing the commit history)

I googled a lot, but couldnt find an appropriate solution, since we dont want to loose the commit history of the prototype branch, we cannot simply create a new branch and push it in the new branch (at least thats how i understood it).

So, what im looking for, is to move, rename or whatever the actual prototype branch without loosing the commit history

Wanted status:

  • original prototype branch renamed to master branch including the commit history
  • original master branch renamed to old branch which holds the (optionally including the commit history)

I'm be thankful for any help!

UPDATE:

of course i found many blogs and links which described how to rename a branch. but i didnt find out if the commit history will still be available, because it sounded like youd just move the current state of the branch into a new branch. But now i just found this answer on stackoverflow which answers my question! So yes, moving a branch with git branch -m also copies the commit history!

thanks for the help!

But still one question remains: What is the difference between these two answers? Is the Outcome the very same, or is there a reason why i would prefer one over the other?

Answer 1:

# Normal state, for me at least
$ git branch
=> master

# Get into your dev branch.
$ git checkout dev
=> dev

# Now we make a new branch `development' based on `dev'
$ git checkout -b development
=> development
$ git branch -d dev

Answer 2:

#rename the local branch to the new name
git branch -m old_name new_name 

#delete the old branch on remote - where <remote> is eg. origin
git push <remote> --delete old_name

#push the new branch to remote         
git push <remote> new_name
x2twelve
  • 55
  • 8

0 Answers0