I have a question regarding renaming a branch in git. I created a local branch dev
and pushed branch to remote. I did lots of work on the dev
branch and am updating remote branch regularly.
Now I want to change the name of the branch from dev
to development
. I know how to rename a branch in GIT.
My question is like if I rename the branch, does commit history to the dev
-branch will be lost or not? If yes, how do i keep my commit-history?
The git branch command lets you rename a branch. To rename a branch, run git branch -m <old> <new>. “old” is the name of the branch you want to rename and “new” is the new name for the branch.
Branches are essentially pointers to a certain commit. Renaming a local Git Branch is a matter of running a single command. However, you can't directly rename a remote branch; you need to push the renamed local branch and delete the branch with the old name.
Now I want to change the name of the branch from dev to development, I know how to rename branch in GIT. My question is like if I rename the branch, does commit history to the dev-branch will be lost or not? If yes, how do i keep my commit-history?
You can simply create a new branch from your dev
branch, and then delete the dev
branch. The new branch will be a copy of your existing branch, I often do this to guard against breaking a branch when rebasing, or merging.
Here's a sample output:
# Normal state, for me at least
$ git branch
=> master
# Get into your dev branch.
$ git checkout dev
=> dev
# Now we make a new branch `development' based on `dev'
$ git checkout -b development
=> development
$ git branch -d dev
You can always check the git log
before the last step, if you prefer. But all branches in Git are just special tagged references. Creating development
from dev
doesn't duplicate everything, so you don't waste any space by keeping it.
As per man pages: git branch -move
- move/rename a branch and the corresponding reflog.
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