Replacing the master branch in git and preventing fast forward

I have a library on github and about a year ago I did a complete rewrite of the app that is not backwards compatible. It is on a branch called ‘structured’.
Now most people who are installing the library are using that branch and I would like to make it the master and move the current master to ‘legacy’.

I don’t want people who were on the old master to be able to fast forward to the new master because it would break their apps for sure. Is it possible to divert them to the legacy branch, or at least throw an exception and display a message telling them to checkout the legacy branch?

  • Deleting branches in git causes gitk to go wild
  • How to make git repo remember all remotes?
  • Tell Git to stop prompting me for conflicts when none really exist?
  • What do the git statistics mean?
  • Simple git post-commit hook to copy committed files to a certain folder
  • How do I create a duplicate remote branch, local branch and start checking in new changes?
  • git, remote access - ssh
  • Cannot run git pull command through php
  • Check if property exists Groovy
  • Error when attempting to modify Git config file in Windows
  • How would working directory look like in tree diagram?
  • How to undo 'git add' before commit?
  • 3 Solutions collect form web for “Replacing the master branch in git and preventing fast forward”

    I don’t think it’s possible unless you implement a hook, but it may not be worth it.

    I think i’d simply clone the repo on my server, leave the old repo as it is, pulling bugfixes if needed and create another repo for the new “structured” library.

    There is no way to divert them, because Git branches are just labels: there is no way to tell that the new master branch is any different than the old one.

    I think it’s a bad idea for a client to clone from the master branch if they don’t want it to break them. You should have release branches or tags for this purpose, and then people can clone from them and they’ll know they have a stable branch that only might get backward-compatible updates (in case of a branch) or never change (in case of a tag).

    As for a warning, it’s not possible either because there is no hook you can put on the server to run when someone fetches from it (only for push you can). You’ll have to just write it clearly on your GitHub page.

    Another idea is to amend the last commit in master so that it’s not a fast-forward of the old master anymore; and do it in a way that causes a conflict. This way, whenever someone with the old master pulls, they will get a conflict and have to check what’s going on.

    As for the “divert” portion of your question, you could always do something like this as the first commit on the new master:

    #ifndef IMPLEMENTED_STRUCTURED
    #error "The master branch of project x has been completely rewritten and will break legacy applications.  If you are unable to update your application, switch to the legacy branch of this project and your code should continue working as before.  If you want to use the new structured code, simply add a preprocessor definition for IMPLEMENTED_STRUCTURED to get rid of this error message."
    #endif
    

    That will keep anyone’s code from compiling successfully until they read the message and decide upon the course of action they want to take.

    Hopefully if you’re not using C/C++ your language has functionality which can enable a similar behavior.

    Git Baby is a git and github fan, let's start git clone.