![]() ![]() Step-4: Reset the upstream branch for the new-name local branchįor every branch that is up to date or successfully pushed, add upstream (tracking) reference: $ git push -set-upstream origin Since we are in a different branch we will execute the following command to perfom the rename:ĪLSO READ: git blame explained in layman's terms OR you must use the following command by specifying both old and new branch name: $ git branch -m you skipped the step-1 above): $ git branch -m If you are still in the same branch (i.e. You can also rename a branch while working in the same branch. This is an optional step and you may choose to ignore it. In this example we will rename issue-7843 to new-issue-7843 in both local and remote repository. So currently I have the following list of branch on my local workstation: git branch Let me pull another branch from my remote repository: git pull origin issue-7843:issue-7843įrom :golinuxcloud/git_examples Now let us rename a git branch in both local and remote repository. Total 4 (delta 1), reused 1 (delta 0), pack-reused 0Īs you can see our main branch is ahead of new-feature branch by one commit: git log -onelineĢ0412c0 ( HEAD -> main, origin/main, origin/HEAD) Added index.html templateĬf00196 (origin/new-feature, origin/issue-7843, new-feature) Added patch-1ĪLSO READ: git push explained with practical examples git rename branch both local and remote ![]() Now we can also push our previously committed changes to the main branch without loosing any changes: git push origin main So our remote branch has been successfully renamed: git branch -remotes Remote: To create a merge request for new-feature, visit: Total 0 (delta 0), reused 0 (delta 0), pack-reused 0 Now let us rename the remote branch using the same syntax as we used earlier, we will rename feature branch to git push origin origin/feature:refs/heads/new-feature :feature New file: git commit -m "Added index.html template" -aġ file changed, 0 insertions(+), 0 deletions(-) Your branch is up to date with 'origin/main'. This is just to make sure my changes are not lost while renaming the remote branch: git status I also have some un-merged changes in my main branch. For example I have a remote branch feature is is not cloned on my local workstation: git branch In this scenario we assume that the remote branch you plan to rename is not cloned locally. Scenario-2: When remote branch is not cloned locally The remote branch has been renamed successfully while the local branch name is still the same: git branch ![]() With this step your old branch will be deleted and a new branch will be created with the new name. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |