Git change branch to master branch9/16/2023 ![]() ![]() If they depend on a specific "origin/master" branch, you might have to change their settings, too. One thing to keep in mind, though, is your toolchain: if you're using a CI/CD tool, GitHub Actions, Azure DevOps / Atlassian Bamboo / GitLab CI pipelines or anything like this, you should check these tools thoroughly. In case you're using the Tower Git client, your colleagues can simply rename their local "master" branch and then change the tracking connection in the contextual menu: Things to Keep in MindĪs you've seen, the process of renaming "master" to "main" isn't terribly complicated. ![]() # Create a new tracking connection with the new "origin/main" branch: # Remove the existing tracking connection with "origin/master": # Get the latest commits (and branches!) from the remote: If other people on your team have local clones of the repository, they will also have to perform some steps on their end: # Switch to the "master" branch: You will then be able to delete the old "master" branch on the remote. In case you are using the Tower Git client, you can rename branches very easily:Īfter creating the new "main" branch on the remote, you might then (depending on your Git hosting platform) have to change the "default" branch or remove any "protected" status for "master". The simplest way to get some commits from one branch to another is cherry-picking. If you try again now, deleting "master" from the remote repository should be successful: $ git push origin -delete master You'll need to resolve this before you can go on. Checkout each branch: git checkout b1 Then merge: git merge origin/master Then push: git push origin b1 With rebase use the following commands: git rebase. Additionally, your old "master" might be set as "protected". ! master (refusing to delete the current branch: refs/heads/master)Įrror: failed to push some refs to like other code-hosting platforms, too, expects you to define a "default" branch - and deleting this is not allowed. In many cases, however, you will see an error message like the following one: To Let's go on and remove the old "master" branch on the remote: $ git push origin -delete masterĭepending on your exact setup, this might have worked and the renaming is successful. ![]() We now have a new branch on the remote named "main". Make sure your current local HEAD branch is still "main" when executing the following command: $ git push -u origin main Instead, we'll have to create a new "main" branch and then delete the old "master" branch. Step 3: Use the -m flag to change the name of the branch. In the second step, we'll have to create a new branch on the remote named "main" - because Git does not allow to simply "rename" a remote branch. So far, so good! The local branch has been renamed - but we now need to make some changes on the remote repository as well! Renaming the Remote master Branch as Well Your branch is up to date with 'origin/master'. Let's quickly check if this has worked as expected: $ git status Many people consider the name main to do a better job of describing this branch and its typical usage.The first step is to rename the "master" branch in your local Git repositories: $ git branch -m master main It implies a relationship with some other, unnamed entity, but it doesn’t represent the unique status of the initial branch. Aside from any offense it may cause, master isn’t a particularly descriptive name anyway. The Git maintainers have worked with the wider development community to address these concerns. Another way to change your default branch in your local machine, as pointed here, is to edit your /. However, the term has become somewhat outdated for its association with colonialism. Other version control systems such as BitKeeper, a predecessor to Git, have also used the term. The master/slave terminology has a long history in computing, especially in reference to hardware such as disk drives. The just-created branch can be renamed via this command: git branch -m To configure the initial branch name to use in all of your new repositories, which will suppress this warning, call: git config -global faultBranch Names commonly chosen instead of 'master' are 'main', 'trunk' and 'development'. This default branch name is subject to change. Using 'master' as the name for the initial branch. Recent versions of Git (2.28 and later) produce the following hint when you create a new repository using git init: ![]() Branch Naming and Why Master Is Being Phased Out ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |