11

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?

Florian Neumann
  • 5,587
  • 1
  • 39
  • 48
Rahul
  • 271
  • 2
  • 9

2 Answers2

10

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.

Lee Hambley
  • 6,270
  • 5
  • 49
  • 81
5

As per man pages: git branch -move - move/rename a branch and the corresponding reflog.

Vitalliuss
  • 1,614
  • 1
  • 12
  • 10