Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it dangerous to create a branch with same name as a deleted branch?

Tags:

git

I've been working on a feature in a branch; call it 'foo'. I'm done for now and merging it into master and would like to delete it locally and remotely. But sometime in the future I may start working on this feature again and will be tempted to create a new branch also called 'foo'.

I don't think this will be a problem for me, but if someone else has their own copy of my current foo branch, and then they try to pull after the new foo branch has been created, will they get screwed up?

like image 274
Sigfried Avatar asked Sep 14 '16 18:09

Sigfried


People also ask

What happens if branch is deleted?

What Happens If I Delete a Git Branch? When you delete a branch in Git, you don't delete the commits themselves. That's right: The commits are still there, and you might be able to recover them.

What happens if you push to a deleted branch?

What happens if I push the way it is? If you git push , it will simply re-create the old branch name on the remote. If you hadn't renamed your branch this would likely be fine assuming you intended to re-use the same branch name, but since you renamed your branch, this is undesirable.

Is it safe to delete branch after merge?

When you're done with a branch and it has been merged into master, delete it. A new branch can be made off of the most recent commit on the master branch. Also, while it is ok to hang onto branches after you've merged them into the master they will begin to pile up.

Should branches be deleted?

They're unnecessary. In most cases, branches, especially branches that were related to a pull request that has since been accepted, serve no purpose. They're clutter. They don't add any significant technical overhead, but they make it more difficult for humans to work with lists of branches in the repository.


1 Answers

No, it's not a problem.

The behaviour would be the same, as if the branch has not been deleted: Git will try to merge (or rebase) them when someone pulls the new branch. If there are conflicts, they would be there in either case.

Branches are, simply, pointers to commits. If you delete a branch, and create another one with the same name later on another commit, this is the same as if you would reset it to that commit (git reset).

like image 144
SevenEleven Avatar answered Sep 23 '22 10:09

SevenEleven