简体   繁体   中英

Archive Github Master Branch and Delete All Files in Master Branch

I'm trying to do what is described here:

Move master branch to another branch and start new master

I have new "Upgraded" project files that I want to replace all the files currently in the master branch.

I've copied the master branch to a archive branch and now I need to reset / delete all the files in the master branch and then sync that with Github.

I've tried running :

git push origin :master

Which tries to delete the master branch but I get this message:

To github.com:fireflysemantics/validatorts.git
 ! [remote rejected] master (refusing to delete the current branch: refs/heads/master)
error: failed to push some refs to 'github.com:fireflysemantics/validatorts.git'

So do we delete the master branch and sync the deletion to Github? Then recreate the master branch and sync the new one with the new files?

You can do this in a simple and straightforward way, that takes multiple steps:

  • Pick or create a new branch to be used as the default.
  • Use the GitHub web interface (or the API) to set this as the default branch.

You can now delete master as you have been attempting. Then you can create a new master , and, if you wish, use the GitHub web interface (or API) to set the new master as the default branch.

Alternatively, you can use git push --force origin new_master:master . This may or may not succeed, depending on what push rights you have, but if it does succeed, it will make GitHub use your new_master branch as its master branch. Remember, the names of branches in your Git repository need not match the names of branches in any other Git repository , including the one on GitHub.

You can rename your own branches at any time. Your branch names are yours . Their branch names are theirs . Just because you and they both have a branch name xyzzy does not mean these are the "same branch" in any useful sense: they are the same if and only if you decree that they are the same, otherwise they are different. We (humans) tend to try to use the same names on "both sides" to maintain our sanity, of course, but that's not a requirement. 1


1 Which of these is not a requirement? Keeping the same names, or being sane? That's for you to decide.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM