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

将本地代码同步到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

第九步,集体总结

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

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理