I have created a local branch X that at some point I pushed to remote server (origin)
git push origin X
I realized it's a bad idea to have branch named X and want it to be called Y The problem is that I've already pushed the branch to the repository.
Is it safe to delete it from the server and push it under a new name like this ?
push origin :X
// 'clone ' the branch under a new name locally ( X-> Y)
push origin Y
What will happen to the people that already fetched from the server. Say that they already made a branch locally based on the old X name BUT they did not make any changes locally or pushed them to the server for the old X branch.
To be precise, renaming a remote branch is not direct – you have to delete the old remote branch name and then push a new branch name to the repo. Step 2: Reset the upstream branch to the name of your new local branch by running git push origin -u new-branch-name .
Rename your remote branchFrom the branches page of your repository, you can rename the branch by clicking the little pencil icon. GitHub will automatically update open Pull Requests.
Renaming a remote repositoryUse the git remote rename command to rename an existing remote. The git remote rename command takes two arguments: An existing remote name, for example, origin. A new name for the remote, for example, destination.
other people will keep a pointer to branch X (as origin/X
) in their repository until they run git remote prune origin
. it's left as a stale branch
when fetching/pulling they will get a second point to (newly created) branch Y (as origin/Y
)
branching and merging is not affected by this.
so, as long as all commits are still reachable from your branch, renaming is fine.
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