You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Notice that you're on the branch corrected-branch-name.
117
+
The corrected branch is available on the remote.
118
+
However the bad branch is also still present on the remote.
119
+
You can delete the bad branch from the remote:
120
+
121
+
[source,console]
122
+
----
123
+
$ git push origin --delete bad-branch-name
124
+
----
125
+
126
+
Now the bad branch name is fully replaced with the corrected branch name.
127
+
128
+
===== Changing the master branch name
129
+
130
+
[WARNING]
131
+
====
132
+
Changing the name of a branch like master/main/mainline/default will break the integrations, services, helper utilities and build/release scripts that your repository uses.
133
+
Before you do this, make sure you consult with your collaborators.
134
+
Also make sure you do a thorough search through your repo and update any references to the old branch name in your code or scripts.
135
+
====
136
+
137
+
Rename your local _master_ branch into _main_ with the following command
138
+
139
+
[source,console]
140
+
----
141
+
$ git branch --move master main
142
+
----
143
+
144
+
There's no _master_ branch locally anymore, because it's renamed to the _main_ branch.
145
+
146
+
To let others see the new _main_ branch, you need to push it to the remote.
147
+
This makes the renamed branch available on the remote.
148
+
149
+
[source,console]
150
+
----
151
+
$ git push --set-upstream origin main
152
+
----
153
+
154
+
Now we end up with the following state:
155
+
156
+
[source,console]
157
+
----
158
+
git branch --all
159
+
* main
160
+
remotes/origin/HEAD -> origin/master
161
+
remotes/origin/main
162
+
remotes/origin/master
163
+
----
164
+
165
+
Your local _master_ branch is gone, as it's replaced with the _main_ branch.
166
+
The _main_ branch is also available on the remote.
167
+
But the remote still has a _master_ branch.
168
+
Other collaborators will continue to use the _master_ branch as the base of their work, until you make some further changes.
169
+
170
+
Now you have a few more tasks in front of you to complete the transition:
171
+
* Any projects that depend on this one will need to update their code and/or configuration.
172
+
* Update any test-runner configuration files.
173
+
* Adjust build and release scripts.
174
+
* Redirect settings on your repo host for things like thee repo's default branch, merge rules, and other things that match branch names.
175
+
* Update references to the old branch in documentation.
176
+
* Close or merge any pull requests that target the old branch.
177
+
178
+
After you've done all these tasks, and are certain the main branch performs just as the _master_ branch, you can delete the _master_ branch:
0 commit comments