关于git:将本地代码同步到gitee和github中去

27次阅读

共计 2996 个字符,预计需要花费 8 分钟才能阅读完成。

将本地代码同步到 gitee 和 github 中去

明天给大家介绍一个怎么应用,把咱们本地的仓库推到 gitee 和 github 下面去。当初近程仓库有两个,一个是 gitee 和 github 近程仓库,地址对应的我本地也就是 work space。

第一步,在 gitee 和 github 中建设仓库地址

注册 gitee 和注册 github,间接通过官网注册

gitee 官网 https://gitee.com/

github 官网 https://github.com/

本地也须要装置 git

第二步,在本地的某个文件夹新家 git 仓库

在本地 D:\work\workspace 中初始化 git

git init

而后在 workspace 中会产生一个.git 的文件夹

第三步,关联近程仓库地址

1. 增加 github

本地仓库 workspace,右键关上 gitbsah,输出上面命令

git remote add github git@github.com:xxxx/javaCore.git

2. 增加 gitee

本地仓库 workspace,右键关上 gitbsah,输出上面命令

 git remote add gitee git@gitee.com:xxx/java-Core.git

以上仓库地址,更具本人注册理论来填写

第四步,批改以后仓库地址中的 .git 的 config 配置

在执行 git init 的文件夹下,关上.git,有一个 config 文件, 批改配置

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
[remote "github"]
    url = git@github.com:xxxx/javaCore.git
    fetch = +refs/heads/*:refs/remotes/github/*
[remote "gitee"]
    url = git@gitee.com:xxx/java-Core.git
    fetch = +refs/heads/*:refs/remotes/gitee/*
[branch "master"]
    remote = origin
    merge = refs/heads/master

将 filemode = false 改为 true

第五步,查看近程仓库地址

执行上面指令

git remote -v

能够查看到有近程仓库地址

$ git remote -v
gitee   git@gitee.com:xxx/java-Core.git (fetch)
gitee   git@gitee.com:xxx/java-Core.git (push)
github  git@github.com:xxx/javaCore.git (fetch)
github  git@github.com:xxx/javaCore.git (push)

以上就是增加实现的仓库地址

第六步,增加密钥,并查看密钥是否可行

1. 生成 ssh 密钥

windows 零碎中关上 cmd

执行上面这个命令

ssh-keygen -t rsa -C xxxxxx@qq.com

而后一路回车健,默认会生成到 C:\Users\DELL\.ssh 这个地址而后关上.ssh,会生成 id_rsa,id_rsa.pub,这一对公私钥,把公钥 id_rsa.pub 用编辑器关上

2. 增加 ssh 密钥

在 gitee 和 github 的个人信息中增加 ssh 公钥,登陆本人 gitee 账户,和 github 账户

3. 查看是否增加胜利

ssh -T git@gitee.com 
ssh -T git@github.com

会呈现 You’ve successfully authenticated。你曾经通过验证

第七步,测试提交代码

1. 增加测试文件

在本地 workspace 中新建一个 test.txt 文件

2. 推送到近程仓库

git pull gitee master
git pull github master
git add .
git commit -m "test file"
git push gitee master
git push github master

在近程端,查看刚刚增加的文件

第八步,常见谬误总结

在这个过程中遇到的一些坑,在上面总结

$ git pull gitee master
From gitee.com:xxx/java-Core
 * branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories


$ git add .

DELL@felix MINGW64 /d/work/workspace (master)
$ git push gitee master
To gitee.com:xxxxx/java-Core.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'gitee.com:xxxx/java-Core.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details



 git pull gitee master
From gitee.com:xxxxx/java-Core
 * branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories

git pull origin master --allow-unrelated-histories
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.


git pull gitee  master --allow-unrelated-histories
From gitee.com:xxxx/java-Core
 * branch            master     -> FETCH_HEAD
Merge made by the 'recursive' strategy.
 LICENSE | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 201 insertions(+)
 create mode 100644 LICENSE


 $ git pull gitee master
From gitee.com:xxxxx/java-Core
 * branch            master     -> FETCH_HEAD
Already up to date

第九步,集体总结

想着已学习的形式,将本地代码,把本地代码同步到不同的近程仓库中去,以记录学习为主目标,把握技能为次要想法,如果有说的或是做的不对的中央,请多斧正,我认为在不同的探讨中必定回得不一样的答案,欢送提出不同的声音,谢谢大家!

正文完
 0