Git推送本地仓库至阿里云仓库

Git推送本地仓库至阿里云仓库

1.安装Git

参考Git安装详解

2.生成 SSH 密钥

基于RSA算法SSH 密钥

1.管理员权限运行Git Bash

2.输入生成密钥指令点击回车,选择 SSH 密钥生成路径。

bash 复制代码
$ ssh-keygen -t rsa -C "2267521563@qq.com"

3.以 RSA算法为例,直接按回车保存默认路径c:\Users\Dexter\.ssh\,也可自定义路径;

windows自定义路径下要进行路径转换 /d/DataBase/Git/.ssh/aliyun_rsa,确保有文件夹D:\DataBase\Git\.ssh

bash 复制代码
Dexter@LAPTOP-MKN50DTQ MINGW64 /d/DataBase/Git/.ssh
$ ssh-keygen -t rsa -C "2267521563@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Dexter/.ssh/id_rsa): /d/DataBase/Git/.ssh/aliyun_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /d/DataBase/Git/.ssh/aliyun_rsa
Your public key has been saved in /d/DataBase/Git/.ssh/aliyun_rsa.pub
The key fingerprint is:
SHA256:wOoDxRDh31238zGxa443UPuqNti25rLvYwqewfyA 2267521563@qq.com
The key's randomart image is:
+---[RSA 3072]----+
|+o*=.            |
| @ +..           |
|o % + E . .      |
| + * o o =       |
|  o . . S *      |
|   o   o o o     |
|    o   +.       |
|     + ++*       |
|    ..B*B++      |
+----[SHA256]-----+

默认路径
[默认]密钥生成路径为:c:\Users\Dexter\.ssh\id_rsa
[默认]公钥生成路径为:c:\Users\Dexter\.ssh\id_rsa.pub

自定义路径
[自定义]密钥生成路径为:D:\DataBase\Git\.ssh\aliyun_rsa
[自定义]公钥生成路径为:D:\DataBase\Git\.ssh\aliyun_rsa.pub

4.输入指令,赋值公钥到剪切板

bash 复制代码
cat /d/DataBase/Git/.ssh/aliyun_rsa.pub | clip

注:如果密钥是默认生成路径就不用管了,直接跳转阿里云工作台添加SSH公钥,如果自定义路径的话继续以下步骤。

5.定位到/c/Users/Dexter/.ssh/路径,新建或者修改config文件;

bash 复制代码
#aliyun
$ cd /c/Users/Dexter/.ssh/
$ touch config
$ vi config

6.修改config文件追加以下内容,意思是访问codeup.aliyun.com时调用我们自定义路径下的公钥。

haskell 复制代码
Host codeup.aliyun.com
HostName codeup.aliyun.com
PreferredAuthentications publickey
IdentityFile /d/DataBase/Git/.ssh/aliyun_rsa

3.添加 SSH 公钥,复制仓库路径

1.登录阿里云工作台,打开个人设置,添加 SSH 公钥

2.回到阿里云项目中,点击克隆,复制SSH路由

4.计算机本地Clone项目

1.打开计算机本地路径,运行Git Bash

2.输入git init初始化 git 仓库,创建新项目时使用的第一个命令,此命令将创建一个空白的新的存储库,然后我们可以将源代码存储在此存储库中。

bash 复制代码
## 初始化
Dexter@LAPTOP-MKN50DTQ MINGW64 /e/WorkSpace/CSharpWork/PCMonitor
$ git init

3.设置安全路径,设置转换字符串

bash 复制代码
## 设置当前路径安全路径
Dexter@LAPTOP-MKN50DTQ MINGW64 /e/WorkSpace/CSharpWork/PCMonitor
$ git config --global --add safe.directory "*";

#提交时转换为LF,检出时转换为CRLF
Dexter@LAPTOP-MKN50DTQ MINGW64 /e/WorkSpace/CSharpWork/PCMonitor
$ git config --global core.autocrlf true
  1. 输入git add .将所有修改过的文件和新文件添加到暂存区
bash 复制代码
Dexter@LAPTOP-MKN50DTQ MINGW64 /e/WorkSpace/CSharpWork/PCMonitor (master)
$ git add .

5.输入git commit 会将更改添加到本地存储库。

bash 复制代码
Dexter@LAPTOP-MKN50DTQ MINGW64 /e/WorkSpace/CSharpWork/PCMonitor (master)
$ git commit -m "first commit"

6.输入git remote将本地存储库连接到远程。

bash 复制代码
Dexter@LAPTOP-MKN50DTQ MINGW64 /e/WorkSpace/CSharpWork/PCMonitor (master)
$ git remote add origin git@codeup.aliyun.com:dexter/PCMonitor/PCMonitor.git

7.输入git pull同步远程仓库文件至本地

bash 复制代码
$ git pull origin master --allow-unrelated-histories

8.输入git push -u origin推送本地仓库内容至远程仓库

bash 复制代码
Dexter@LAPTOP-MKN50DTQ MINGW64 /e/WorkSpace/CSharpWork/PCMonitor (master)
$ git push -u origin

6.常见问题

1.fatal: detected dubious ownership

解决办法:git config --global --add safe.directory "*"参考链接

bash 复制代码
Dexter@LAPTOP-MKN50DTQ MINGW64 /e/WorkSpace/CSharpWork/PCMonitor
$ git add .
fatal: detected dubious ownership in repository at 'E:/WorkSpace/CSharpWork/PCMonitor'
'E:/WorkSpace/CSharpWork/PCMonitor' is owned by:
        BUILTIN/Administrators (S-1-5-32-544)
but the current user is:
        LAPTOP-MKN50DTQ/Dexter (S-1-5-21-3087508804-2382978303-3275827262-1001)
To add an exception for this directory, call:

        git config --global --add safe.directory E:/WorkSpace/CSharpWork/PCMonitor

Dexter@LAPTOP-MKN50DTQ MINGW64 /e/WorkSpace/CSharpWork/PCMonitor
$ git config --global --add safe.directory "*";

2.warning: LF will be replaced by CRLF the next time Git touches it

解决办法:git config --global core.autocrlf true参考链接

bash 复制代码
Dexter@LAPTOP-MKN50DTQ MINGW64 /e/WorkSpace/CSharpWork/PCMonitor (master)
$ git add .
warning: in the working copy of 'FrmDefault.cs', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'FrmLoading.Designer.cs', LF will be replaced by CRLF the next time Git touches it

3.error: failed to push some refs to 'codeup.aliyun.com:xxx.git'

解决办法:git pull origin master --allow-unrelated-histories 参考链接

bash 复制代码
Dexter@LAPTOP-MKN50DTQ MINGW64 /e/WorkSpace/CSharpWork/PCMonitor (master)
$ git push -u origin master
Enter passphrase for key '/d/DataBase/Git/.ssh/aliyun_rsa':
To codeup.aliyun.com:dexter/PCMonitor/PCMonitor.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'codeup.aliyun.com:dexter/PCMonitor/PCMonitor.git'
hint: Updates were rejected because the remote contains work that you do not
hint: have locally. This is usually caused by another repository pushing to
hint: the same ref. If you want to integrate the remote changes, use
hint: 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

4.大文件请使用 Git-LFS 管理

解决方法:git lfs install,git lfs track "*.dll"参考链接

使用说明: https://help.aliyun.com/document_detail/321367.html

bash 复制代码
Dexter@LAPTOP-MKN50DTQ MINGW64 /e/WorkSpace/CSharpWork/PCMonitor (master)
$ git push -u origin master
Enter passphrase for key '/d/DataBase/Git/.ssh/aliyun_rsa':
Enumerating objects: 1216, done.
Counting objects: 100% (1216/1216), done.
Delta compression using up to 8 threads
Compressing objects: 100% (1181/1181), done.
Writing objects: 100% (1215/1215), 597.77 MiB | 2.36 MiB/s, done.
Total 1215 (delta 322), reused 0 (delta 0), pack-reused 0 (from 0)
remote: Resolving deltas: 100% (322/322), done.
remote: 推送失败,以下文件大小超过单文件 200MB 的系统限额:
remote: Blob ID  | 大小(MB) | 文件名
remote: -------------------------------
remote: 831335ba | 206.51   | libcef.dll
remote:
remote: 大文件请使用 Git-LFS 管理,使用说明: https://help.aliyun.com/document_detail/321367.html
To codeup.aliyun.com:dexter/PCMonitor/PCMonitor.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'codeup.aliyun.com:dexter/PCMonitor/PCMonitor.git'
相关推荐
但老师1 小时前
Git遇到“fatal: bad object refs/heads/master - 副本”问题的解决办法
git
秃头女孩y1 小时前
git创建分支
git
研究是为了理解6 小时前
Git Bash 常用命令
git·elasticsearch·bash
DKPT6 小时前
Git 的基本概念和使用方式
git
划水小将军8 小时前
阿里云函数计算GBK编码
阿里云·云计算
Winston Wood9 小时前
一文了解git TAG
git·版本控制
喵喵先森10 小时前
Git 的基本概念和使用方式
git·源代码管理
xianwu54311 小时前
反向代理模块
linux·开发语言·网络·git
binishuaio13 小时前
Java 第11天 (git版本控制器基础用法)
java·开发语言·git
会发光的猪。14 小时前
如何在vscode中安装git详细新手教程
前端·ide·git·vscode