The default git branch in Android Studio is 'master'. However, Github has updated its default to 'main', and I'd like to keep consistent with that. Is there any way to change the default git branch when using version control within Android Studio?
Clarification: I know that I can switch branches after the repo is created, but let's say there is no repo yet. I go to VCS > Import into Version Control > Share Project on Github , and it creates a repo with default settings, 'master' branch. I want to change the settings so that the default branch on creation is 'main' or whatever I want it to be.
I don't want to have to create a new branch after the repo is initialized. If I'm going to take extra steps, I'll just use the CLI. Just not what I'm looking for.
You can rename your local branch created to the name you want. For example master to main so that local branch matches to your remote branch. Follow the steps:
I stumbled upon this problem as well and after searching all over this worked for me. Open the terminal tab in the bottom left of Android Studio, then enter
git config --global init.defaultBranch main
After enabling VCS for a new project, the branch is automatically set to main instead of master . You will still need to change the branch name for existing repos.
To confirm your default branch at anytime (before or after the previous command), simply omit the branch name
git config --global init.defaultBranch
Credit goes to VonC's answer. Instructions to change existing repo branch also in his answer.
EDIT: So it didn't end up working for me. According to further research ,
"Git has always created an initial first branch with the name master... Starting in Git 2.28, git init will instead look to the value of init.defaultBranch when creating the first branch in a new repository."
Since I am using Linux Mint 20.2, which is based on Ubuntu Focal, my version of Git is stuck at 2.25. This might explain why it doesn't work for me.
Looking through all the Settings in the IDE, I was unable to find an option to change the default branch. However, someone in Jetbrain's YouTrack confirmed that
"the IDE does not instruct git to use any specific name, so there is no need to wait for any specific support to rename the branch. Git 2.28 introduced the setting to control the default branch name... So you can set it globally to have main (or any other name) in new repositories".
In summary, try installing a version of Git that is 2.28 or above, and with the mentioned init.defaultBranch configuration variable, it should work.
I hope.
main
default branchgit config --global init.defaultBranch main
this will globally change the default branch to the main
$ git branch -m master main
main
branch using git push -u origin main
master
branch git push origin --delete master
for detailed solution checkout
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.