0

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?

Ole
  • 41,793
  • 59
  • 191
  • 359

1 Answers1

0

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


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

torek
  • 448,244
  • 59
  • 642
  • 775
  • I like the second option, as it would make the work flow really simple. However when I ran: `Github/validatorts $ git push --force origin master1:master Everything up-to-date` it said everything up to date, but the new `master1` branch did not show up on Github? Any ideas? – Ole Sep 28 '21 at 08:36
  • "Everything up to date" means that all the commits your Git was asked to send (your `master1` commits) were already present in the target Git (over on `origin`) *and* **their** `master` already selected the same *last* commit as your `master1`. So they did not change anything in their repository. Are you sure your `master1` points to the desired last commit? (See ["Pretty Git branch graphs"](https://stackoverflow.com/q/1057564/1256452) to see how to view your own Git's graph.) Remember that they'll be using the name `master`, which your Git will reflect in your own `origin/master`. – torek Sep 28 '21 at 16:05