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?
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 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.
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.
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.
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
).
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