admin管理员组

文章数量:1122846

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.

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.

Share Improve this question asked Nov 21, 2024 at 18:06 SomeDudeSomeDude 14.2k5 gold badges24 silver badges48 bronze badges 5
  • Basically its "Merge remote-tracking origin/main into branch_a" is what I see in gitlab after I do those commands - you also did git push, didn't you? – Arkadiusz Drabczyk Commented Nov 21, 2024 at 18:27
  • Yes I did git push too. – SomeDude Commented Nov 21, 2024 at 19:25
  • And you did git merge origin/main while you were on branch_a? – Arkadiusz Drabczyk Commented Nov 21, 2024 at 19:39
  • Yes I did a git merge origin/main while on branch_a and no body uses branch_a – SomeDude Commented Nov 21, 2024 at 19:47
  • right, see my answer then – Arkadiusz Drabczyk Commented Nov 21, 2024 at 20:06
Add a comment  | 

2 Answers 2

Reset to default 1

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.

Yes, it is safe to delete a remote branch (branch_a) after merging the main branch into it. You merged main into branch_a meaning that branch_a is now updated with all changes from main. If you have any new changes that are important in the branch_a make sure you make a pull request to the main before deleting the branch_a locally or remotely.

本文标签: gitlabDeleting remote branch after git merge originmainStack Overflow