5

I have a project hosted on my own personal git server (it is not on GitHub). The master branch is a stale old cookie, and I don't need it anymore.

A couple of months ago I created a 0.8/develop branch off of master and since then we've gone through 0.8/master, 0.9/develop, 0.9/master and we're currently on 1.0/develop. I'd like to get rid of the master branch, mainly because it doesn't match the naming convention that we've established. It's just a matter of housekeeping.

I found several related questions on SO, as well as a blog post, but they all seem to be specific to use of GitHub, and not my own private server:

These both specifically say something to the effect of:

You need to go to the main GitHub page for your forked repository, and click on the 'Settings' button.

Of course, this is not an option as I'm not using GitHub. I'm guessing that I can edit the contents of the config file in my bare repo to achieve the same results. Is that correct? The config file currently looks like this:

[core]
        repositoryformatversion = 0
        filemode = true
        bare = true
        logallrefupdates = true
        ignorecase = true
        precomposeunicode = false
        sharedRepository = group
[remote "origin"]
        url = file:///Library/WebServer/Documents/loupe
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master

I have two questions:

  1. Should I set my default repo to my current working branch (1.0/develop), or the oldest branch that's left (0.8/develop)?
  2. What modifications do I need to make to the config file to set the default repo?
Community
  • 1
  • 1
Ben Harold
  • 6,242
  • 6
  • 47
  • 71
  • `git push origin :master`, `git remote prune origin` – madhead Jul 09 '13 at 21:36
  • @madhead remote: error: By default, deleting the current branch is denied, because the next remote: error: 'git clone' won't result in any file checked out, causing confusion. – Ben Harold Jul 09 '13 at 21:37
  • Basically you're trying to do something that you really don't need to do. Just leave master out of date, or keep it up to date, whatever you choose. There's no reason to delete it. –  Jul 09 '13 at 22:02
  • 1
    @NathanBouscal I agree that I don't *need* to delete it, but I *want* to. – Ben Harold Jul 09 '13 at 23:35
  • The feedback Git is giving you is telling you why deleting it is a bad idea. What will people who clone your repo have checked out by default? You're basically putting in a substitute master that points to something else, because there has to be a default branch. Why not just have that default branch be master to begin with? –  Jul 09 '13 at 23:41
  • @NathanBouscal We're versioning our repo, so the default should probably be `0.9/master` or `1.0/develop` – Ben Harold Jul 09 '13 at 23:55
  • 1
    Versions should be tags. I'd recommend this: http://nvie.com/posts/a-successful-git-branching-model/ –  Jul 10 '13 at 01:26

1 Answers1

7

First decide which branch should be the default branch when the repository is cloned. I assume new_master for this example.

On one of the clients create the new_master branch on the remote repository, you may use anything for master instead, e.g. a commit or another branch name, or skip this step if you already have a suitable branch on the remote.

git push origin master:new_master

The next step can't be done from remote, so execute the command in your remote repository (e.g. using SSH):

cd /path/to/my_git_repo
git symbolic-ref HEAD refs/heads/new_master

Alternatively, change the content of the HEAD file directly.

Back on the client:

git fetch
git remote show origin

You should see that the HEAD points to new_master instead of master (or that HEAD is ambiguous if you set new_master to be master). Now we can remove the old master:

git push origin :master

Git shouldn't complain anymore about the deletion. Finally, set the local refs/remotes/origin/HEAD:

git remote set-head origin -a
nif
  • 3,342
  • 20
  • 18
  • Awesome! Would you advise choosing the older `0.8/develop` or the newer `1.0/develop` as the new master...or does it matter? – Ben Harold Jul 09 '13 at 23:27
  • 1
    It's just the branch which is checked out when someone clones the repository for the first time. Our `master` / `HEAD` reflects the current production state, while other branches are used for active development. But that's just our workflow. Set it to whatever fits your workflow. – nif Jul 09 '13 at 23:36
  • This is even more relevant now with GitHub leading the industry in changing the language of technology. (https://github.com/github/renaming/) I found this StackOverflow question/answer because I want to rename my 'master' branch to 'main'. Thank you. – Elyrith Jan 08 '21 at 23:54