Fix error when using invalid branch name when creating a new pipeline
## What does this MR do?
This MR fixes `500` error when creating a new pipeline though user interface ("Run pipeline")
## Are there points in the code the reviewer needs to double check?
Is this a good approach to catch those exceptions on `Repository` level?
## Does this MR meet the acceptance criteria?
- [x] [Changelog entry](https://docs.gitlab.com/ce/development/changelog.html) added
- Tests
- [x] Added for this feature/bug
## What are the relevant issue numbers?
Closes#23982
See merge request !7324