git 双库操作
单仓库
初始化:git 仓库
- git init //初始化仓库
- git add .(文件name) //添加文件到本地仓库 --
- git commit -m “first commit” //添加文件描述信息
- git remote add origin 远程仓库地址 //链接远程仓库,创建主分支
- git pull origin master // 更新本地仓库
- git push -u origin master //把本地仓库的文件推送到远程仓库
多仓库模式 使用第一种 带有仓库名称的模式
方法一 使用 “git remote add 仓库名” 命令 --推荐
第一个仓库(origin 默认仓库 )
git remote add origin https://github.com......
第二个仓库(local 便是第二仓库)
git remote add local https://github.com......
取消第二仓库关联:
git remote remove local
查看关联库 git remote -v
local https://github.com/lixy-github/newRepository.git (fetch)
local https://github.com/lixy-github/newRepository.git (push)
origin http://....com:5678/gitbucket/git/Li.XY/Pride.git (fetch)
origin http://....com:5678/gitbucket/git/Li.XY/Pride.git (push
可以看到两个远程仓库地址,但是需要push两次(每一个仓库都需要单独push)
方法二:(使用 “git remote set-url” 命令)
- git remote set-url --add newRepository https://git.hub.com/......
- git remote -v
- newRepository https://github.com/lixy-github/newRepository.git (push)
- origin http://....com:5678/gitbucket/git/Li.XY/Pride.git (fetch)
- origin http://....com:5678/gitbucket/git/Li.XY/Pride.git (push)
可以看到远程仓库有两个 push 地址,这种方法的好处是每次只需要push一次就可以了。
方法三: 打开 .git/config 找到 [remote "github"],添加对应的 url 即可,效果如下。这种方法其实和方法二是一样的。
- [remote "github"]
- url =http://....com:5678/gitbucket/git/Li.XY/Pride.git
- fetch = +refs/heads/*:refs/remotes/github/*
- url = https://github.com/lixy-github/newRepository.git
方法二和方法三在push的时候比较方便,但是只有1个拉取地址,而方法一有2个拉取地址和2个push地址,可以灵活操作两个仓库,所以个人推荐方法一。
多仓库拉取代码 [name] 为仓库配置名称 可以用
查看
git remote -v
- 拉取
git pull origin master
- 关联远程仓库
git remote add origin https://github.com/....
提交
git add .
git commit –m “描述”
git push -u origin master 推送到默认仓库 origin
git push -u origin master 推送到默认仓库 origin
两个远程场无法pull 同步
Git :fatal: refusing to merge unrelated histories解决
把本地仓库和Github上关联以后,发现git pull,git feach提醒fatal: refusing to merge unrelated histories
原因是两个分支是两个不同的版本,具有不同的提交历史 加一句
$git pull origin master --allow-unrelated-histories
可以允许不相关历史提,强制合并,确实解决了这个问题

浙公网安备 33010602011771号