If there is a repository that I only have git://
access to (and would usually just push+pull), is there a way to rename branches in that repository in the same way that I would do locally with git branch -m
?
The git branch command lets you rename a branch. To rename a branch, run git branch -m <old> <new>. “old” is the name of the branch you want to rename and “new” is the new name for the branch.
Git Branch Rename Command The steps to change a git branch name are: Rename the Git branch locally with the git branch -m new-branch-name command. Push the new branch to your GitHub or GitLab repo. Delete the branch with the old name from your remote repo.
Now that the current remote name is confirmed — you can change it by running this command: git remote rename beanstalk origin. This command tells git to rename the current remote to something different. In this example, we're changing the remote name to “origin”, but you can change your remote to be anything you want.
Select the repo you want to rename under Git repositories on the left and select .... Select Rename repository... from the menu. If the Repositories pane is not expanded, select > to expand it and display the list of repositories. Enter a new repo name in the Repository name field in the dialog, then select Rename.
You just have to create a new local branch with the desired name, push it to your remote, and then delete the old remote branch:
$ git branch new-branch-name origin/old-branch-name $ git push origin --set-upstream new-branch-name $ git push origin :old-branch-name
Then, to see the old branch name, each client of the repository would have to do:
$ git fetch origin $ git remote prune origin
NOTE: If your old branch is your main branch, you should change your main branch settings. Otherwise, when you run $ git push origin :old-branch-name
, you'll get the error "deletion of the current branch prohibited".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With