【在家办公】代码上传公司远端GitLab仓库
查看本地的git 如何添加远程仓库
1.查看远程仓库地址
git remote -v
此时若什么都没有显示说明,git无远程仓库。
2.添加ssh协议的远程仓库
git remote add origin git@github.com:**********.git
再次查看,即可查看到2个远程仓库的链接
origin git@gitlab.com:**********.git (fetch)
origin git@gitlab.com::**********.git (push)
当前,我本机就是用的这种方式连接的github,好处是每次提交代码时,不需要重复来回输入用户名和密码,这就是ssh秘钥的好处。
使用家里的WiFi长传到github上的代码时,报出如下错误:
$ git push origin 分支名称
ssh: connect to host github.com port 22: Connection refused
fatal: Could not read from remote repository.
得知第一种协议被禁掉后,只能换一种连接进行合并本地仓库了。继续往下看另一种协议。
3.切换成 https协议连接github
建立本地仓库和远端GitLab仓库的关联关系
git remote add origin https://gitlab*********************.git
在这一步时如果出现错误:fatal:remote origin already exists
先清除一下关联关系:
git remote rm origin
再重新关联:
git remote add origin https://gitlab*********************.git
检查关联是否已建立且正确
git remote -v
注意:因为我们是在家办公,我们公司的gitlab域名映射成了ip我们直接把`域名换成IP地址`
# 添加http链接协议
git remote add origin http://ip:port/*********************.git
参考链接:https://blog.csdn.net/s740556472/article/details/80318886