If you find this article helpful, don’t hesitate to share it with your friends and family. Oftentimes, renaming branches locally and remotely might be inevitable, so that’s why I wrote this article to help you rename your branches without costly errors. In the case of this tutorial, I’m using Github as the client and the renaming was successful:īranches are an awesome feature of Git that make your hosted software project safer. To confirm that you successfully renamed the remote repo, log into your client's website and check the repo. So, for the example, this would be git push origin -u bug-fixes Step 2: Reset the upstream branch to the name of your new local branch by running git push origin -u new-branch-name. In the example I’ve been using, this would be git push origin -delete mistake-fixes Let’s see what our branches look like now. We checked out the feature19 branch and renamed it to feature18. git checkout feature19 git branch -m feature18. Then use the git branch command with the -m (move) option. Step 1: Delete the old name by running git push origin -delete old-branch-name To rename the current branch, make sure you’ve checked out and are using the branch you want to rename. 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.įollow the steps below to rename a remote git branch: Renaming a remote branch is not as straightforward as renaming a local branch. N.B.: Make sure you verify that the branch has been renamed by running git branch -a to see all branches. git branch -m < oldname > < newname > Example 3: git rename branch git branch m old-name new-name git push origin :old-name new-name git push origin u new-name Example 4: change local branch name git branch -m < newname > Example 5: git rename branch from local 1.If you are on another branch, for example, main and you want to rename the branch from there, run git branch -m old-name new-name You can see that the branch has been renamed from mistake-fixes to bug-fixes Step 3: To rename the branch, run git branch -m new-name To switch to a branch, run git switch branch-name or git checkout branch-name. In this case, I’m going to switch to the mistake-fixes branch so I can rename it bug-fixes. Step 2: Switch to the branch you want to rename by running git checkout branch-name. Step 1: To see the branches you have, run git branch -list or git branch -a Sometimes, you might want to change the name of a branch because of typos or other errors, and that’s what I’m going to show you how to do in this guide. You can also add new features and fix bugs on a different branch without affecting the original code. Different people working on a software project can work in different branches before merging their changes with the original code. Git is a version control system that software developers use to keep track of changes in their applications and collaborate with others.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |