Git things: Renaming your working branch

I drafted this post years ago and never hit “Publish”. 🙂

As a developer, I have been working with various proprietary tools for most of my professional life. Recently, I started working on some personal projects where I needed to use Git, an open-s…


This content originally appeared on DEV Community and was authored by ls

I drafted this post years ago and never hit "Publish". :)

As a developer, I have been working with various proprietary tools for most of my professional life. Recently, I started working on some personal projects where I needed to use Git, an open-source tool for version control. I have to admit, I made silly mistakes while navigating Git at first. But, with some practice and research, I have learned how to use it effectively.

Something I struggled with initially was renaming a working branch in Git. It's a common task that developers need to do quite often, but I found it challenging initially. After some research and experimentation, I have come up with a goto-guide.

Here is my step-by-step guide to rename a working branch in Git on both local and remote setups:

Renaming a branch locally

First, navigate to the local branch that you want to rename using the command:

git checkout <branch-name>
Then, rename the branch using the command:

git branch -m <new-branch-name>
This will rename the current branch to the new branch name.

Pushing renamed branch to remote

After renaming the branch locally, push the changes to the remote repository using the command:

git push origin -u <new-branch-name>
This will push the renamed branch to the remote repository.

Deleting old branch on remote

If you want to delete the old branch from the remote repository, use the command:

git push origin --delete <old-branch-name>
This will delete the old branch from the remote repository.

That's it! You have successfully renamed a working branch in Git on both local and remote setups.

Happy coding!


This content originally appeared on DEV Community and was authored by ls


Print Share Comment Cite Upload Translate Updates
APA

ls | Sciencx (2023-05-21T19:30:37+00:00) Git things: Renaming your working branch. Retrieved from https://www.scien.cx/2023/05/21/git-things-renaming-your-working-branch/

MLA
" » Git things: Renaming your working branch." ls | Sciencx - Sunday May 21, 2023, https://www.scien.cx/2023/05/21/git-things-renaming-your-working-branch/
HARVARD
ls | Sciencx Sunday May 21, 2023 » Git things: Renaming your working branch., viewed ,<https://www.scien.cx/2023/05/21/git-things-renaming-your-working-branch/>
VANCOUVER
ls | Sciencx - » Git things: Renaming your working branch. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/05/21/git-things-renaming-your-working-branch/
CHICAGO
" » Git things: Renaming your working branch." ls | Sciencx - Accessed . https://www.scien.cx/2023/05/21/git-things-renaming-your-working-branch/
IEEE
" » Git things: Renaming your working branch." ls | Sciencx [Online]. Available: https://www.scien.cx/2023/05/21/git-things-renaming-your-working-branch/. [Accessed: ]
rf:citation
» Git things: Renaming your working branch | ls | Sciencx | https://www.scien.cx/2023/05/21/git-things-renaming-your-working-branch/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.