gitgitlab

Deleting remote branch after git merge origin/main?


I created a remote branch lets say "branch_a" off of origin/main. Then to keep the branch upto date, I did:

git fetch origin
git merge origin/main

I hope that's one of the right ways? I mean git rebase would also do. But git merge origin/main is also legal I assume?

Basically its "Merge remote-tracking origin/main into branch_a" is what I see in gitlab after I do those commands. Yes I use gitlab.

Now question is it is safe to delete this remote branch branch_a without affecting anything right?

Please suggest best practice if I did something incorrect.


Solution

  • Now question is it is safe to delete this remote branch branch_a without affecting anything right?

    Well it depends on multiple factors and what does without affecting anything mean.

    Users who ran git fetch while the branch existed will have it listed in git branch -r forever until they run git fetch --prune. It only takes space and might be confusing but will not break anything.

    Users who created a local branch from it and let Git set up remote branch automatically with git checkout <BRANCH> will not be able to pull from it any more.

    Any PRs that were open against this branch should be immediately closed, at least that's what Bibucket and GitHub are doing.

    Pushing a new branch may trigger CI systems build, depending on how it's configured and how many times it pulls the repository it may crash at some point because the commit on the tip of the branch was gone.

    These won't be serious issues in most cases, especially if you didn't ask anyone to check out the branch (still, some users may do that on their own). And if you have it locally and someone else might need it again you can re-push it or restore it from reflog within the next 30 days.