一.安装

1. 下载安装包地址,为windows环境64位的安装包Git-2.46.0-64-bit.exe

2.安装Git  官方地址 软件包下载 使用指导文档

双击Git-2.46.0-64-bit.exe,安装路径可修改,其余全部默认,全部默认也可以,安装完成后,在任意目录空白处鼠标右键,可以看到有Open Git Bash here即正确安装。

二.gitlab配置全局SSH公钥

1.windows生成公钥

空白处鼠标右键---Open Git Bash here

#生成公钥  默认3个回车
ssh-keygen.exe
#拷贝公钥
cat /c/Users/Administrator/.ssh/id_ed25519.pub
  • 1.
  • 2.
  • 3.
  • 4.

代码发布之windows环境gitlab 配置免密_windows

gitlab  偏好设置---SSH密钥

代码发布之windows环境gitlab 配置免密_git_02

三.windows环境演示git与gitlab的交互操作

1.gitlab新建项目 

项目名称Shell_Scripts   
分配置到root组  
取消勾选 使用自述文件初始化仓库
  • 1.
  • 2.
  • 3.

代码发布之windows环境gitlab 配置免密_免密_03

2.命令行指引

#Git 全局设置
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"

#创建一个新仓库
git clone git@192.168.77.147:root/shell_scripts.git
cd shell_scripts
git switch -c main
touch README.md
git add README.md
git commit -m "add README"
git push -u origin main

#推送现有文件夹
cd existing_folder
git init --initial-branch=main
git remote add origin git@192.168.77.147:root/shell_scripts.git
git add .
git commit -m "Initial commit"
git push -u origin main

#推送现有的 Git 仓库
cd existing_repo
git remote rename origin old-origin
git remote add origin git@192.168.77.147:root/shell_scripts.git
git push -u origin --all
git push -u origin --tags
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.

3.将本地现有代码推送到远程仓库演示  

进入到本地代码仓库---空白处鼠标右键---Open Git Bash here

代码发布之windows环境gitlab 配置免密_免密_04

#Git 全局设置
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"
#初始化
git init
#查看远程认证
git remote -v
#重命名远程认证
git remote rename origin old-origin
#添加远程配置
git remote add origin git@192.168.77.147:root/shell_scripts.git
#添加到缓存区并提交到本地仓库
git add .
git commit -m "V0.1"
#打标签
git tag -a "v0.1" -m "v0.1"
#推送本地代码到远程仓库
git push -u origin --all
git push -u origin --tags
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.

gitlab上查看

代码发布之windows环境gitlab 配置免密_免密_05

#补充
#查看远程认证
git remote -v
#删除远端认证
git remote remove origin
git remote remove old-origin
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.

报错No refs in common and none specified; doing nothing.


##推送本地代码到远程仓库
git push -u origin --all
#报错
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch.
fatal: the remote end hung up unexpectedly
remote:
remote: ========================================================================
remote:
remote: rpc error: code = Canceled desc = user canceled the push
remote:
remote: ========================================================================
remote:
error: failed to push some refs to '192.168.77.147:root/shell_scripts.git'
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.

解决:

git add .
git commit -m "V0.1"
#推送本地代码到远程仓库
git push -u origin --all
git push -u origin --tags
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.