SAN FRANCISCO -- At least once every time Bob Melvin visited San Francisco as a visiting manager, he allowed himself to believe that maybe someday, he would wear a Giants uniform again.
Running the bleachers before games, Melvin would glance out at iconic McCovey Cove. Before the team locked up the 60-foot Coca-Cola slide beyond left field, he used to take good-luck, head-first plunges, too.
On Wednesday, after buttoning up his new No. 6 Giants jersey as the franchise's 39th manager, Melvin called it "surreal" that this moment was actually happening.
After 20 years as a big league manager -- including a recent, turbulent end to his time managing the rival San Diego Padres -- the soon-to-be 62-year-old Melvin is coming home with a three-year contract.
"I think probably every series, I would look in that dugout and look over to the other side and say, 'Maybe someday, hopefully,'" Melvin said. "There were always times here, I can admit that now, that I was hoping at some point in time I'd come back."
The Padres, meanwhile, will start anew after a two-year relationship with Melvin that ended with a third-place finish after an 82-80 season, despite a $258 million payroll that was third-highest in the majors.
"I think, as we went through the process the last two years, like any relationship, there were things you liked [and] there were things that we felt we could've done better," Padres general manager A.J. Preller said Wednesday.
"For us, there clearly was a path forward -- that we have a good group and could have success. But this gives us an opportunity to really start focusing on adding a manager that from our standpoint fits what we're trying to do -- fits our team and our clubhouse, and somebody that's going to help lead this club here moving forward."
Melvin, who missed the playoffs this season after reaching the NL Championship Series in 2022, didn't address a reported rift in his relationship with Preller other than to say another season in San Diego would have been difficult.
"I think there was a narrative at the end that probably wasn't going to go away, me being on the last year of my contract," Melvin said. "I think as far as that organization goes, it's probably not fair if that narrative continued through next year.
"So all things considered, this opportunity came about, and for all the reasons I stated this feels like the right one for me, but I very much enjoyed my time in San Diego. It just seemed like with a lot of things that were popping up there, it was time to move on."
A native of nearby Palo Alto, California, Melvin attended the University of California-Berkeley and played for his hometown Giants from 1986-88. He also managed across the Bay in Oakland for a decade.
And now he's back, replacing Gabe Kapler, who was fired with three days remaining in the Giants' season after going 295-248 over three-plus years, including a franchise-record 107 wins in 2021.
Even with another year remaining on Melvin's contract, San Diego granted permission for the Giants to pursue him. There will be no compensation due to the Padres.
Giants president of baseball operations Farhan Zaidi thanked San Diego "for being accommodating and allowing us to pursue the perfect candidate and for giving Bob the opportunity to come home."
"If a team called and asked about permission, we feel it's in the best interest of everybody to at least let the employee know, 'Hey, this is what's out there,'" Preller said about the discussions with the Giants. "From Bob's standpoint, he was pretty open that that was the one job, at least when the Giants called, that at least he had to listen."
Padres bench coach Ryan Flaherty and Padres senior advisor Mike Shildt are expected to interview for San Diego's managerial vacancy this week.
"There's a lot of interest in this job," Preller said Wednesday. "We've had some very interesting names and some people that are very accomplished that have expressed interest in this job. Really, it's a testament to our team, our roster, the talent that's here, the fact that we've gone to the playoffs a couple times here in the last few years, and our city. We have amazing fans here that support this team. So it's an attractive job."
Zaidi, whose relationship with Melvin dates to their time together in Oakland, also agreed to a new deal Wednesday that coincides with Melvin's pact through the 2026 season.
"We just view Bob as the perfect manager and perfect leader for this team and this organization right now," Zaidi said. "... Hearing from players how passionate they are about playing for him, about his leadership, about his care for them, there are so many players out there who played for Bob who to this day will say he is the best manager they've ever played for, and that carried so much weight for us."
Melvin, a three-time Manager of the Year who has won the award in both leagues, went 171-153 with the Padres. He has a career record of 1,517-1,425 with eight postseason appearances while guiding Arizona, Seattle, Oakland and San Diego.
ESPN's Alden Gonzalez and The Associated Press contributed to this report.