... | @@ -469,31 +469,9 @@ branch. That process is more involved. |
... | @@ -469,31 +469,9 @@ branch. That process is more involved. |
|
|
|
|
|
Changing the name of a default branch both locally and on remotes can
|
|
Changing the name of a default branch both locally and on remotes can
|
|
be partially automated with the use of [anarcat's branch rename
|
|
be partially automated with the use of [anarcat's branch rename
|
|
script](https://gitlab.com/anarcat/scripts/-/blob/main/git-branch-rename-remote). This script performs the following tasks:
|
|
script](https://gitlab.com/anarcat/scripts/-/blob/main/git-branch-rename-remote). The script basically renames the branch locally, pushes
|
|
|
|
the new branch and deletes the old one, with special handling of
|
|
```
|
|
GitLab remotes, where it "un-protects" and "re-protects" the branch.
|
|
# rename the branch locally if not already done
|
|
|
|
git show-ref refs/heads/master > /dev/null && \
|
|
|
|
git branch --move master main
|
|
|
|
git fetch origin
|
|
|
|
# fix HEAD pointer for local remote branch
|
|
|
|
git symbolic-ref refs/remotes/remote/HEAD refs/remotes/remote/main
|
|
|
|
# push branch remotely if it doesn't exist (or fix tracking branch if it does)
|
|
|
|
git branch -u origin/main || exit
|
|
|
|
git push -u origin main
|
|
|
|
# fix remote HEAD pointer on remote repository
|
|
|
|
ssh example.com git symbolic-ref HEAD main
|
|
|
|
# delete old branch
|
|
|
|
git push -d origin master
|
|
|
|
```
|
|
|
|
|
|
|
|
If the `ssh` step fails, it will try to do the equivalent over the
|
|
|
|
GitLab API, that is:
|
|
|
|
|
|
|
|
1. unprotect the old branch
|
|
|
|
2. protect the new branch
|
|
|
|
3. change the default branch
|
|
|
|
4. *then* `git push -d` to delete the old branch
|
|
|
|
|
|
|
|
You should run the script with an account that has "Maintainer" or
|
|
You should run the script with an account that has "Maintainer" or
|
|
"Owner" access to GitLab, so that it can do the above GitLab API
|
|
"Owner" access to GitLab, so that it can do the above GitLab API
|
... | | ... | |