1

In keeping with the times, GitHub has changed terminology from master to main, but my TortoiseGit still uses master as the name of the main branch.

So when I push my local repo to Github, there are now 2 branches in GitHub (main and master) which causes confusion.

How to make TortoiseGit change to using main as the default?

likejudo
  • 3,396
  • 6
  • 52
  • 107
  • 2
    Side note: *terminology* is the wrong word here. *Terms* might be OK, but it's simpler to just say "change branch names". This also leads you directly to the answer: if you want to change a branch name, ask Git (or TortoiseGit) to change the branch name ([here's how](https://stackoverflow.com/q/36133271/1256452)). – torek May 17 '21 at 00:37
  • It's more than just renaming, you also need to change the remote default branch on GitHub. – MrTux May 17 '21 at 08:43
  • 1
    Actually GitHub has not changed anything. You are totally free to call the branch master. It will work fine. – matt May 17 '21 at 08:49

3 Answers3

2

This is set in the .gitconfig file You want

[init]
    defaultBranch = main

Through tortoisegit you would do settings→Git→Edit systemwide gitconfig and change defaultBranch from "master" to "main". This requires admin. Alternatively you could edit the global .gitconfig and add the section above.

poompt
  • 248
  • 1
  • 8
1

Branches are just labels for commits (including their history). Also, all branches are basically the same, but we decided ("arbitrarily") that one is the one we do our main work on (this branch could also be named dev, default or something else).

You have several ways to achieve to have a main branch. One is:

  1. Create a new local branch main that should be your new main branch from now on (you might want to fetch the remote repository before to get the latest changes)
  2. Push that branch to GitHub and select "Set upstream/track remote branch" (you might need to push with "force" to hard overwrite the remote branch on GitHub).
  3. On GitHub go to the project settings -> Branches and select main as your new default branch (can also be done using git remote set-head origin -a on the CLI.
  4. Delete your local master branch and the remote master branch on GitHub. (Basically you can also decide to keep your old master branch for some time so that the transition is easier for other people using your repository. Then, however, you need to merge the change of your main branch to the old master regularly.)

There might be easier ways, but based on your question it is not clear what your current state in the repository currently is.

An alternative could be to switch to a new temporary branch (name doesn't matter, should not be main), rename your current local master branch to main using the Reference Browser, and then proceeding with step 2 (make sure the remote branch is also named main). Then, switch to the new main branch and finally delete the temporary branch.


If you want to have main as the default for new repositories, you need to set the Git default using git config --global init.defaultBranch main on the CLI (this does not change any exitsing repositories).

MrTux
  • 32,350
  • 30
  • 109
  • 146
  • Technically there needs to be a step 0 which would check out `master`, to ensure that `main` created in step 1 points to `master`. – jingx May 16 '21 at 20:17
  • How to make TortoiseGit change to using main as the default? – likejudo May 19 '21 at 11:28
  • @likejudo Whatv do you mean by "How to make TortoiseGit change to using main as the default?"? – MrTux May 22 '21 at 15:18
  • TortoiseGit uses `master` as the name of its default branch – likejudo May 23 '21 at 16:19
  • @likejudo Are you talking about new repositories or old ones? For old ones, just rename the branch and you're done. Branches are just labels and we decide how we name them. Please be really specific on what you are talking about! – MrTux May 23 '21 at 17:58
  • With a new repository, TortoiseGit uses `master` as the default name. One can select either `main` or `master` as the default name only when TG was **first installed**. After that it uses the initial choice for all repos. It appears that one must uninstall and then reinstall it for it to offer `main` as the default name. – likejudo May 25 '21 at 23:54
  • TortoiseGit does not ask what name should be used as the default. It fully relies on Git, see my answer. – MrTux May 26 '21 at 07:00
  • Not clear, have to search for more detailed information to find where i can change the default branch when creating a new repository – Shenron Nov 03 '22 at 08:38
1

As pointed out by @torek, master is not a special branch. You can just rename it to main by typing the following on git:

git branch -M <old name> <new name>

I dont know how to do that in tortoise git. But you should be able to google how to change branch name in tortoise git and follow the instructions

Hemil
  • 916
  • 9
  • 27