How to reset master branch of GIT server (and local)


Usually the master branch is the default branch for the repository. So, is it necessary to do some steps before.

  • Move the current local master branch. New name “old_master”
# git branch -m master old_master
  • Create a new local master branch without parents
# git checkout --orphan master

Now the new master branch has no history

  • Remove any files from file system (in the repository) and in git
# rm -rf *
# git rm -rf *
  • Create a new File. Example LICENSE and add it to git
# touch LICENSE
# git add *
  • Do a Commit
# git commit -am 'Reset Master Branch.'
  • Force a Push to origin master branch. Be careful to not have the option “denyNonFastforwards” set to true in the config file located in the repository of the Git Server. In case yes, change it to false.
        repositoryformatversion = 0
        filemode = true
        bare = true
        sharedrepository = 1
        denyNonFastforwards = false
# git push -f origin master
  • Remove the old_master branch
# git branch -D old_master