小工具知识网

当前位置: 首页 > 行业知识 > Git推送本地仓库至阿里云仓库

行业知识

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

2026-11-10 06:30:09 来源:互联网转载

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

1.安装Git

参考Git安装详解

2.生成 SSH 密钥

基于RSA算法SSH 密钥

1.管理员权限运行Git Bash

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

$ 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

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_rsaEnter passphrase (empty for no passphrase):Enter same passphrase again:Your identification has been saved in /d/DataBase/Git/.ssh/aliyun_rsaYour public key has been saved in /d/DataBase/Git/.ssh/aliyun_rsa.pubThe key fingerprint is:SHA256:wOoDxRDh31238zGxa443UPuqNti25rLvYwqewfyA 2267521563@qq.comThe 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.输入指令,赋值公钥到剪切板

cat /d/DataBase/Git/.ssh/aliyun_rsa.pub | clip

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

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

#aliyun$ cd /c/Users/Dexter/.ssh/$ touch config$ vi config

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

Host codeup.aliyun.comHostName codeup.aliyun.comPreferredAuthentications publickeyIdentityFile /d/DataBase/Git/.ssh/aliyun_rsa

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

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

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

4.计算机本地Clone项目

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

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

## 初始化Dexter@LAPTOP-MKN50DTQ MINGW64 /e/WorkSpace/CSharpWork/PCMonitor$ git init

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

## 设置当前路径安全路径Dexter@LAPTOP-MKN50DTQ MINGW64 /e/WorkSpace/CSharpWork/PCMonitor$ git config --global --add safe.directory "*";#提交时转换为LF,检出时转换为CRLFDexter@LAPTOP-MKN50DTQ MINGW64 /e/WorkSpace/CSharpWork/PCMonitor$ git config --global core.autocrlf true
  1. 输入git add .将所有修改过的文件和新文件添加到暂存区
Dexter@LAPTOP-MKN50DTQ MINGW64 /e/WorkSpace/CSharpWork/PCMonitor (master)$ git add .

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

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

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

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

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

$ git pull origin master --allow-unrelated-histories

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

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 "*",参考链接

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/PCMonitorDexter@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,参考链接

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 itwarning: 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 ,参考链接

Dexter@LAPTOP-MKN50DTQ MINGW64 /e/WorkSpace/CSharpWork/PCMonitor (master)$ git push -u origin masterEnter 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 nothint: have locally. This is usually caused by another repository pushing tohint: the same ref. If you want to integrate the remote changes, usehint: '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

Dexter@LAPTOP-MKN50DTQ MINGW64 /e/WorkSpace/CSharpWork/PCMonitor (master)$ git push -u origin masterEnter 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 threadsCompressing 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.dllremote:remote: 大文件请使用 Git-LFS 管理,使用说明: https://help.aliyun.com/document_detail/321367.htmlTo 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'

上一篇:托管服务器怎么操作?

下一篇:个人怎么购买阿里云服务器?