Git 使用

本地新建的仓库怎么和远程新建的毫不相关的仓库合并?

git branch -a 查看分支

  1. 先设置remotes 为远程分支地址.
  2. 设置本地分支与远程分支的追踪: git branch --set-upstream-to=origin/master master
  3. 然后使用rebase 把远程分支合并进入 本地master;
    note: 如果分支可以force push 在建立好追踪关系后,直接强制Push就ok!

note: rebase命令可以把不相关的历史合并在一起。

Git 使用SSH连接到远程仓库[解决多个密钥对使用问题]

初次使用[只有一个密钥对]

确定已经安装好git bash 以github为例

# 序号代表步骤
# 1.生成密钥对
 ssh-keygen -t ed25519 -C "your_email@example.com"
#   注:如果您使用的是不支持 Ed25519 算法的旧系统,请使用以下命令:
 ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
#   出现: "Enter a file in which to save the key" 请输入一个密钥对的名称! 不输入则默认为id_rsa
# 2. 将 SSH 私钥添加到 ssh-agent
#  如果执行以下命令时出现:  "Could not open a connection to your authentication agent."错误信息,就需要手动启动ssh-agent,跳到步骤3,没有则跳到步骤4
 ssh-add ~/.ssh/id_ed25519 # 私钥文件名
# 3.确保 ssh-agent 正在运行。没有就手动启动下, 启动好后再执行步骤2
 eval `ssh-agent -s`
# 4. 把生成的公钥添加到git远程仓库中,这一步Github中执行!
# 5. 验证是否连接成功, 出现提示信息: Are you sure you want to continue connecting (yes/no)? 输入: yes 回车
 ssh -T git@github.com
# 6.出现: " Hi username! You've successfully authenticated... "的相关信息,连接成功!

添加多个密钥对

在还需要添加新的密钥对,重复上面步骤完成后,还需要在密钥目录新建一个config的文件;
如果在有多个密钥对情况下添加config文件,在不同的目录或者不同的IDE下,可能会出现下面的错误提示:

git@gitee.com: Permission denied (publickey).
Could not read from remote repository.
		
Please make sure you have the correct access rights
and the repository exists.

config文件内容如下:

Host gitee.com
IdentityFile ~/.ssh/webstorm-gitee

config格式说明:

Host 后面接密钥对应的github域名(或者其他远程仓库对应的域名),IdentityFile 后面为对应私钥的存储目录.

如果您的私钥没有存储在默认位置之一(如 ~/.ssh/id_rsa),您需要告知 SSH 身份验证代理其所在位置。 要将密钥添加到 ssh-agent;

Git 设置代理[解决连接GitHub太慢或者超时失败问题]

# 设置代理
git config http.proxy http://127.0.0.1:10809
git config https.proxy https://127.0.0.1:10809

# 设置为全局代理
git config --global http.proxy http://127.0.0.1:10809
git config --global https.proxy https://127.0.0.1:10809

# 取消代理设置
git config --global --unset http.proxy
git config --global --unset https.proxy

# 查看config配置
git config --global -e

解决: no supported authentication methods avaiable

在(小乌龟)向github远程推送文件的时候会报错 no supported authentication methods avaiable

解决方法:因为git(小乌龟)和Git的冲突我们需要把乌龟git设置改正如下。

1. 找到TortoiseGit--》Settings(设置)--》Network(网络)
2. 将SSH client指向E:\git\Git\usr\bin\ssh.exe (我的Git工具安装E盘)
posted @ 2021-03-15 23:31  那年长安  阅读(88)  评论(0)    收藏  举报