gitbranchgit-branchremote-branch

When is it safe to delete local branch?


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.


Solution

  • 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.