I have a basic understanding of git, but I'm not expert (or even intermediate) with it.
We have a team of people working on a project. A feature branch was created that multiple people worked on. Now we are done working on that feature branch, and are ready to merge it back into main.
My questions are:
How do I ensure that after the feature branch is merged into main, no developers continue to accidentally work on the feature branch? Can I prevent them from pushing changes to the feature branch?
It depends on your hosting platform. Github and Gitlab protect a branch so that no one or only authorized roles are allowed to update/delete the branch. Gerrit gives access of a branch to specific users. If your server is as simple as git-daemon, you can write git hooks like pre-receive
to prevent branch updating or deleting.
Will deleting the feature branch accomplish this? What happens if I delete the feature branch, but somebody tries to push changes to it?
It depends. If a user has permission to create a branch, a new branch will be created on push, with a side-effect that the branch head may be an unexpected commit. If the user does not, the push will fail.
If I delete the feature branch, will that lose the change history for commits made to that feature branch?
When you delete a branch, only a reference is deleted. The commits and other meta data are still there. The difficulty of finding these commits back also depends on the hosting platform. It would be quite easy if the feature branch has been merged to another branch (not by squash merge). If you use pull requests/merge requests/pending changes, the platform creates special internal references on the commits and finding them back is also easy with the help of these references.