When is it safe to delete local branch?
Asked Answered
L

4

10

The situation is like this:

I created remote branch from other remote develop branch -> fetched it to local -> made some changes -> git add -> git commit -> pushed to remote and made pull request.

Pull request is still there and branch hasn't been merged yet.

Is it safe to delete local branch that hasn't been merged yet?

I don't want to have bunch of local branches that I don't need anymore.

Latter answered 14/7, 2015 at 8:27 Comment(0)
C
11

It's technically safe to delete a local branch once you've pushed it to a remote branch , as you could always retrieve your changes back from your remote branch, even if the pull request is not merged yet.

However, I'd wait with it until the pull request is actually merged. The whole idea behind having pull requests, as opposed to allowing anyone to just merge what they want, is to allow a feedback loop between the developer and the maintainer of the project. Depends on the project's etiquette and the level of trust the maintainer has towards you, it may take several roundtrips of improvements before your pull requests is merged. I'd avoid the hassle of having to recreate your local branch each time and just leave it there and work on it until the request is finally merged.

Cartilaginous answered 14/7, 2015 at 8:37 Comment(0)
C
2

It is safe to delete your local branch after you pushed your changes to your own remote repository.

The pull request is unrelated to this, because it is simply a request to the maintainers of the original repository to merge your changes back into their code base. For that, they need access your remote repository, but of course not to your local files.

Cryptozoic answered 14/7, 2015 at 8:32 Comment(0)
R
1

The remote will have all the commit objects that contain your work, so you could remove your local branch, though why bother?

Branches are extremely light weight (being just 40 byte pointers in the repository to the commit object). Your repository and the external will have the same commit objects, and should you be required to do further work before the pull request is accepted, you'll have an easier job moving to your local branch than if you delete it and have to pull down your own change and work off that.

Respond answered 14/7, 2015 at 8:33 Comment(2)
it doesn't matter if pull request hasn't been accepted yet, everytime I start working on some feature or bugfix I need to create new branch from remote develop, so after I push my branch I no longer need it localy.. ist just simple matter of my little OCDLatter
I know all about OCD :-)Respond
B
0

I had a situation where I deleted a branch, then I was unable to change back to the main branch under any circumstances. Plastic acted like it wanted that unused branch back and would never allow me to do anything useful with that repository again.

I am very new to Plastic - so I probably should have contacted support - but I was in a hurry. My solution was to start a new repository from scratch. It was a bit painful - but it works again. And now I know not to go deleting things since there may be dependencies that I don't understand.

So, while I trust the experts here, I recommend that you really know that you can delete the branch without experiencing the problem that I had.

I am going to post this question in another thread: When is NOT safe to delete an unused branch?

Bighorn answered 12/10, 2019 at 14:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.