ArturoAP
ArturoAP

Reputation: 432

Delete Git branch after creating a child branch

really quick one, I am currently reorganizing my Git repository, but i have doubt about this situation and i don't want to mess it up, i am currently using Visual Studio 2015 and Git Lab.

I have these branches A(master) & Bqwerty(develop), Bqwerty doesn't have a proper name convention, so i was thinking of renaming it or creating a branch out of it with the proper name and then delete Bquerty afterwards.

Neither Visual Studio 2015(team explorer) or GitLab offer the option to rename branches (or at least i couldn't find it),

Is it safe to run:

git branch -m <newname>

Will it affect Visual Studio or Git Lab?

Or if i do make a new branch Bqwerty --> B and then delete Bqwerty, will this preserve the history even if B hasn't been merged yet?.

Upvotes: 0

Views: 408

Answers (2)

ArturoAP
ArturoAP

Reputation: 432

I ran into minor trouble when i renamed with

git branch -m <newname>

The local branch Bqwerty was successfully renamed to B, but it was still pointing to origin/Bqwerty.

So what i ended up doing was create a new remote branch (origin/B) from origin/Bqwerty, afterwards i used:

git push -u origin B:B

to point my local B branch to origin/B branch.

Finally i deleted my remote origin/Bqwerty branch, and everything is working ok now :D

Upvotes: 0

Joseph K. Strauss
Joseph K. Strauss

Reputation: 4913

I do not know about the tools you mentioned, but based on my knowledge of Git a branch rename would work just fine.

In Git, branches are merely pointers to commits. This history is stored in the commits, so a rename merely makes a new pointer that points to the same commit as the old branch. In this way it almost exactly the same as creating and deleting.

The only difference is that a rename will preserve the reflog across the rename while create/delete will not.

The reflog is a log of the commits a particular branch or reference has pointed to. This is something that is local to one repository, and is not shared when pushing/fetching. This is not the standard Git history which is really the commit history which does not really car about branch names, and is shared with push/fetch.

Upvotes: 2

Related Questions