设置 git 远程源

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7259535/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 11:45:02  来源:igfitidea点击:

Setting up a git remote origin

git

提问by Jay

I have the following repos.

我有以下回购。

  1. DEV REPO: in a directory on my development machine where i make changes
  2. MAIN REPO: bare repository on my development machine to which i push changes from dev repo
  3. PRODUCTION REPO: repository on host machine to pull updates from the main repo
  1. DEV REPO:在我进行更改的开发机器上的目录中
  2. 主仓库:我的开发机器上的裸仓库,我从开发仓库推送更改
  3. 生产存储库:主机上的存储库以从主存储库中提取更新

I used git remote add origin /Users/me/sites/main_repoto set the MAIN repo as origin for the DEV repo. The PRODUCTION repo is on a remote host. Can i use a variation of the same command to set the MAIN repo as origin for the PRODUCTION repo also? If "yes", then i suppose the syntax would include an ip address. What would that look like?

我曾经git remote add origin /Users/me/sites/main_repo将 MAIN 存储库设置为 DEV 存储库的来源。生产存储库位于远程主机上。我是否可以使用相同命令的变体来将 MAIN 存储库设置为 PRODUCTION 存储库的来源?如果“是”,那么我想语法将包括一个 ip 地址。那会是什么样子?

回答by Clement Herreman

Using SSH

使用 SSH

git remote add origin ssh://login@IP/path/to/repository

Using HTTP

使用 HTTP

git remote add origin http://IP/path/to/repository

However having a simple git pullas a deployment process is usually a bad ideaand should be avoided in favor of a real deployment script.

然而,使用简单git pull的部署过程通常是一个坏主意,应该避免使用真正的部署脚本。

回答by lostphilosopher

For anyone who comes here, as I did, looking for the syntax to changeorigin to a different location you can find that documentation here: https://help.github.com/articles/changing-a-remote-s-url/. Using git remote addto do this will result in "fatal: remote origin already exists."

对于像我一样来到这里的任何人,寻找原点更改为不同位置的语法,您可以在此处找到该文档:https: //help.github.com/articles/changed-a-remote-s-url/. 使用git remote add这样做将导致“致命:远程源已经存在”。

Nutshell: git remote set-url origin https://github.com/username/repo

简而言之: git remote set-url origin https://github.com/username/repo

(The marked answer is correct, I'm just hoping to help anyone as lost as I was... haha)

(标记的答案是正确的,我只是希望能帮助像我一样迷路的人......哈哈)

回答by Michael Thompson

You can include the branch to track when setting up remotes, to keep things working as you might expect:

您可以在设置遥控器时包含要跟踪的分支,以使事情按您预期的那样工作:

git remote add --track master origin [email protected]:group/project.git   # git
git remote add --track master origin [email protected]:group/project.git   # git w/IP
git remote add --track master origin http://github.com/group/project.git   # http
git remote add --track master origin http://172.16.1.100/group/project.git # http w/IP
git remote add --track master origin /Volumes/Git/group/project/           # local
git remote add --track master origin G:/group/project/                     # local, Win

This keeps you from having to manually edit your git config or specify branch tracking manually.

这使您不必手动编辑 git 配置或手动指定分支跟踪。