简体   繁体   English

将远程添加到 GitHub 存储库

[英]Add a remote to a GitHub repository

I have a GitHub repository, say https://github.com/mrpandey/proj .我有一个 GitHub 存储库,比如https://github.com/mrpandey/proj

On my local clone of this repo, I have the following two remotes (both fetch and push):在这个 repo 的本地克隆上,我有以下两个遥控器(获取和推送):

ser    ssh://git@server.com:2222/proj.git
origin https://github.com/mrpandey/proj.git

ser is the git server of a platform where I deploy this project. ser是我部署这个项目的平台的 git 服务器。 To automate the deployment process, I was writing a GitHub Actions workflow.为了自动化部署过程,我正在编写一个 GitHub 操作工作流。 The workflow needs to push to ser whenever changes are pushed to main branch of GitHub (origin).每当将更改推送到 GitHub 的main分支(源)时,工作流都需要推送到ser

The problem is that ser is not added as a remote on origin .问题是ser没有作为远程添加到origin I verified this by running git remote -v in the workflow script.我通过在工作流脚本中运行git remote -v来验证这一点。

So, how can I add a remote to the GitHub repo?那么,如何向 GitHub 存储库添加遥控器?

I tried pushing my local to the origin, but ser doesn't show up on origin.我尝试将我的本地推到原点,但ser没有出现在原点上。 GitHub does not provide shell access through ssh, so can't even run remote add on origin. GitHub 不提供通过 ssh 的 shell 访问,因此甚至无法在源上运行remote add

One way is I could run remote add in the workflow script itself.一种方法是我可以在工作流脚本本身中运行remote add However, I would like to know if there is actually a possibility to add another remote to a GitHub repository without the help of GitHub Actions.但是,我想知道是否真的有可能在没有 GitHub Actions 帮助的情况下将另一个远程添加到 GitHub 存储库。

Your remotes aren't part of the repository;您的遥控器不是存储库的一部分; they're not pushed to github when you push your changes.当您推送更改时,它们不会推送到 github。 Remotes need to be configured in each individual working directory.需要在每个单独的工作目录中配置遥控器。

You would need to configure the remote in your workflow script by running the appropriate git remote add ... command:您需要通过运行适当的git remote add ...命令在工作流脚本中配置远程:

git remote add ser ssh://git@server.com:2222/proj.git

Then you could run git push ser然后你可以运行git push ser

Alternately, you can push directly to a git URL.或者,您可以直接推送到 git URL。 For example, your workflow script could run:例如,您的工作流脚本可以运行:

git push ssh://git@server.com:2222/proj.git

Of course, for this to work, you'll need to have ssh keys configured appropriately.当然,要使其正常工作,您需要适当配置 ssh 密钥。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM