$ git push origin -delete masterĪnd that’s it! We’ve now been able to update our local branch, change our remote master branch and rename master to main, plus update our local branch and local git repository. What we should see now is success that we’ve been able to delete the old initial branch called master and finish the process to change over to our main branch. If we don’t perform this step we’ll see a remote rejected error when we attempt to delete this git branch.įrom our local machine we can issue a delete command to the remote GitLab server to delete the old default branch, which was the master branch. This will unprotect what was once our default branch, known previously as the master branch. Just click the yellow Unprotect button to the right. Now that’s done, we can go and unprotect our master branch which is going to allow us to delete it. Once we’ve changed this to main and saved, we can scroll down a little further and make changes to our Protected branches by protecting our new main branch.īy default, Maintainers are allowed to push and merge to a protected branch, so you may wish to either select these default settings or specify your own if you use custom settings for your current master branch. At the top of the settings page is the Default branch Head on over to your repository on or self-hosted GitLab instance and go to Settings -> Repository. This will allow us to avoid a remote rejected type error message when deleting our old master branch in our git repository. You’ll need to make sure that you have at least Maintainer level access to be able to do this in GitLab. Now that we have a new branch remotely, we need to make sure that we change the default branch in the project settings. Your branch is up to date with 'origin/main'. $ git push -u origin mainĪt this stage we should be able to see that now our local repository is up to date with the remote branch name. This allows us to update our existing projects with a new default branch and change the default branch name.Īs long as we are on our “main” branch still as we were before, we can push this new branch to the remote repository. Unfortunately for us we need to create a brand new branch remotely and then update references to it in places like the default branch, protected branches and perhaps even our GitLab CI file too. This hasn’t resulted in a remote renamed branch. Our existing tracking connection is still pointing to master. Your branch is up to date with 'origin/master'.Įxcellent, now that we can see that we have been successful in renaming our local branch we can do the same on our remote repository too as everything we have done so far has not left our computer.Īt this stage we have just updated the current local head branch but we haven’t updated our remote repository. Now we can run anther one liner that will tell us if we were successful $ git status Later on we also need to look at renaming the remote master branch and changing the default branch name in the git repository. This will update your local master branch but not the remote branch. To rename your local “master” branch on your machine, you’ll just need to run a simple one liner command. Renaming Your Local “Master” Branch To “Main” We can also update our tracking connection. By renaming our git branch to a new main branch, we can result in ‘main’ as our new branch. The master slave terminology can sometimes make people feel isolated in the same sense that master slave is sometimes similarly associated with blacklist whitelist. Many want to follow best practices and trends and change their git repo master to main. Git repositories are one of the most popular source tracking tools in use today and renaming master to main has become more of a spotlight recently due to the master slave type notion that it implies. Here we talk about using GitLab to rename master branch to main. If you are still using “master” as the default Git branch name then you may be thinking about renaming your branch on existing projects. You don’t even need to create a new git repository. Going from master to main doesn’t have to be daunting, in fact changing our git repositories master branch name from master to main can be quite a quick and easy process to follow. GitLab has previously made the Phase 1 change to users. Other code hosting platforms like GitHub have made the change and GitLab as another one of the public git hosting platforms has also made the change as of version 14.0 for self-hosted versions that shipped on June 22, 2021. Git and the tech community as a whole has recently been transitioning to using the term “main” to describe the new default branch.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |