Home > other >  Why is there two init.defaultbranch entries in my gitconfig file?
Why is there two init.defaultbranch entries in my gitconfig file?

Time:01-28

I am fairly new to git and in the process of setting up my global configurations, I changed the defaultbranch from master to main. I thought it was fine until I pushed a project to a private bonobo server (for work) and the solution shows up in the repository browser under a master branch with my initial branch (main) under it. I checked my git settings and now I am seeing two entries for the init.defaultbranch section.

The entries are the same now because I went into the gitconfig file and changed the name there, before I realized that this is where my issue may be.

I am running git version 2.34.1.windows.1

If anyone knows what might be causing this issue (basically, what did I mess up) I would appreciate it.

Two entries of init.defaultbranch

CodePudding user response:

First, the default branch should be (by convention) main, not Main.

Second, changing a setting won't change your existing branches.
See "How to Rename the master branch to main in Git"

git branch -m master main
git push -u origin main
git push origin --delete master

CodePudding user response:

The reason you're seeing this is that you have two different configuration files with the same entry. You can see which file each option is from by running git config -l --show-origin.

Note that branch names are case sensitive, and so Main is not the same as main. On some systems in some circumstances, branches and other refs may appear to be case insensitive because they happen to be stored in the file system, but in other contexts, that ends up not being the case. You have to assume they're always case sensitive.

If the branch is already called master, you can rename it by running git branch -m master main. However, in this case, it sounds like you've set the branch correctly, but your Git server sets the default branch to master and doesn't automatically reset it when you push your first branch. If that's the case, you'll need to go into the repository settings on your Git server and set the default branch to the value you want (main).

  •  Tags:  
  • Related