git 远程仓库放多个项目,Permission denied 问题解决

目的: 只建立一个remote,如github上一个项目A,然后本地不同的项目都放在A中。
方案:通过提交不同的分支来解决
博客内容
1)本地项目提交到github上项目的分支
2)Permission denied (publickey) 问题的解决
3 ) 当前目录下clone 远程分支
4)submodule 修改和提交

本地项目提交到github上项目的分支

思路:本地的项目建立一个branch,然后直接提交到remote。

参考 http://www.imooc.com/wenda/detail/557797
具体如下

cd local_project
# 如果没有master需要先建立
git init 
git add .
#  git config user.email ""
#  git config user.name ""
git commit -m "first add"

# 如果有master且有一次提交就
git branch local_brance
git checkout local_brance
git remote add github 。。。
git push github local_brance

如果本地和远程分支名不同

git push --set-upstream github master:server

常用

.git/config

基础的配置

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "github"]
    url = https://changhongjian:ghp_xxx@github.com/changhongjian/xxx.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
    remote = github
    merge = refs/heads/main

保存密码

git config --global credential.helper store

Permission denied (publickey) 问题的解决

如果经常使用两个remote,就容易导致这个问题。一般最好不要设置–global

git config --global --unset user.name
git config --global --unset user.email

# 重新指定
git config user.email ""
git config user.name ""

也可以用 git config --edit 手动编辑

接下来需要按照 https://www.cnblogs.com/wmr95/p/7852832.html
上面这个博客非常好,它竟然把我所有报的错误的情况都列上去了。

我这里大致记一下

ssh-keygen -t rsa -C "xxx@163.com"
# 三个回车,并看到保存的位置 /path/.ssh/id_rsa 一般是 ~/.ssh/id_rsa

#ssh -v git@github.com
#ssh -T git@github.com
# 有错误继续
#ssh-agent -s
#ssh-add /path/.ssh/id_rsa
#ssh-add ~/.ssh/id_rsa
# 有错误继续
eval `ssh-agent -s`
#ssh-add /path/.ssh/id_rsa
ssh-add ~/.ssh/id_rsa

#vim /path/.ssh/id_rsa.pub
vim ~/.ssh/id_rsa.pub
# +yy 复制,然后放到你的github seetings里面的 SSH keys

ssh -T git@github.com
#这样就正常了,可以提交了
git push github xxx

名字不是 id_ras 的配置

Host github.com
    HostName github.com
    IdentityFile X/.ssh/your_name

当前目录下clone 远程分支

mkdir your_dir
cd your_dir
git init
git remote add github xxxx
git fetch github your_remote_brance #(似乎不需要分支名)
#git checkout -b your_remote_brance --track github/your_remote_brance
git checkout -b your_remote_brance
git pull github your_remote_brance

跟踪仓库

 git push --set-upstream github pc

submodule 的问题

如果修改了submodule ,或者建立了新的branch,并进行提交,需要注意在root 项目中还需要 git add 一下。
如果更改 branch 可能还需要,加一下这个

git config -f .gitmodules submodule.your_subproject.branch new_branch

合并分支

合并两个本地分支,直接在某个分支下运行 git merge a_branch 就可以产生冲突文件,然后自己修改
合并本地和远程分支

# 先 fetch 下来
git fetch origin develop
# 查看下不同的地方
git log -p dev_changhongjian..origin/develop
git merge origin/develop # 如果有问题就修改
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值