The above screenshot is the Git client - Fork which I used daily basis for commit code, writing my commit message, and etc.
However, I am wondering how the branch rename work under the hood. Is it as easier as what the UI flow showed us or what we saw was just the abstract of the complex work?
If you interested in what is the action under the hood for the branch rename, then this post might be helpful to you. Without further ado, let's start.
For this section we would separate it two parts.
Rename a local branch was easier and it can simply just done using a single command.
git branch -m old_branch new_branch
For e.g, you would like to a local branch named feature/payment to feature/deposit. Here is the command you need to run.
git branch -m feature/payment feature/deposit
If you already push your branch to the remote, which means your code repository in the cloud. Then you need more steps to rename the local & remote branch
Now, you shall realized rename a remote branch is similar to create a new branch with new name, after that delete the old branch. Let's see how we do it via the CLI.
# 1.) Rename a branch git branch -m old_branch new_branch # 2.) Push latest renamed local branch to remote and reset upstream git push origin -u new_branch # 3.) Delete the old remote branch git push origin -d old_branch
Something worth mention here is the 2nd command
-u options. It basically allow you to reset your new branch upstream tracking. Otherwise, it would still tracking the old_branch as remote upstream.
Lastly, you might think do I need to really know this complicated command stuff? Why not just use the Git client.
Well, it's really depend on your preference. It's just like everyone have their own preference.
So feel free to have your own preferred ways of doing stuff. However, CLI command allows you to use git command in server environment where you do not have the User Interface.
I hope you enjoy this article and I will see you in next article.