How can I set bseurl so that the site works on the local server and github

If you really want to drop the base url locally without code change you can set the value in config and then start locally as

jekyll serve --baseurl ''

That is an empty string override.