I currently have two protected branches in my GitLab repo, but want to rename master to prod.
From my research I found some steps and wanted to make sure they were correct:
First way:
# Unprotect branch
# Switch to old local branch
git checkout master
# Create and switch to new local branch
git checkout -b main
# Delete old remote branch
git push --delete origin master
# Delete old local branch
git branch -D master
# Push new local branch to remote and set upstream branch
git push --set-upstream origin main
# Reprotect branch
Second way:
# Unprotect branch
# Rename local branch
git branch -m master prod
# Delete old remote branch and push the new local branch
git push origin :master prod
# Switch to new local branch
git checkout prod
# Reset the upstream branch for the new local branch
git push origin -u prod
# Reprotect branch
CodePudding user response:
Technically, you can create prod
before unprotecting and deleting master
, but yes, the steps you describe will work.
CodePudding user response:
Yes, your steps look correct. Note that you can just create a new branch rather than "rename" master. You can do this entirely in the GitLab UI. The steps are roughly something like this:
- Create
prod
branch based onmaster
. - Set
prod
as a protected branch and configure rules similar to your currentmaster
. - Unprotect
master
- Delete
master
.