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'
相关推荐
每天八杯水D1 小时前
Git完整使用经历
git
xianwu5433 小时前
反向代理模块。开发
linux·开发语言·网络·c++·git
DashVector4 小时前
如何通过HTTP API检索Doc
数据库·人工智能·http·阿里云·数据库开发·向量检索
@泽栖4 小时前
阿里云-将旧服务器数据与配置完全迁移至新服务器
服务器·阿里云
前端_库日天5 小时前
部署自己的git托管平台
git·ubuntu·docker
神仙别闹7 小时前
基于C#实现的(WinForm)模拟操作系统文件管理系统
java·git·ffmpeg
刘大辉在路上17 小时前
突发!!!GitLab停止为中国大陆、港澳地区提供服务,60天内需迁移账号否则将被删除
git·后端·gitlab·版本管理·源代码管理
老刘莱国瑞20 小时前
STM32 与 AS608 指纹模块的调试与应用
python·物联网·阿里云
小林coding21 小时前
阿里云 Java 后端一面,什么难度?
java·后端·mysql·spring·阿里云
Anna_Tong1 天前
云原生大数据计算服务 MaxCompute 是什么?
大数据·阿里云·云原生·maxcompute·odps