配置本地git到gitlab并推送

前言

  • gitlab仓库地址:git@192.168.0.12:godev/gohello.git

步骤

复制代码
# 配置用户
git config --global user.name "zhangsan"
git config --global user.email "zhangsan@gmail.com"
# 查看配置
git config --list
# 如果没ssh公钥,则生成一个。会生成在$HOME/.ssh
# id_rsa为私钥,id_rsa.pub为公钥
ssh-keygen -t rsa
# 将公钥内容配置到gitlab中
# 克隆仓库
git clone git@192.168.0.12:godev/gohello.git
# 编写代码
# 添加当前目录下所有文件到git暂存区
git add .
# 提交并填写提交信息
git commit -a -m "edit main.go"
# 推送到远程仓库的master分支
git push origin master

补充

  • 克隆
复制代码
# 克隆远程仓库的dev分支到本地当前目录,新目录名为gohello
git clone -b dev git@192.168.0.12:godev/gohello.git
# 克隆远程仓库的dev分支到本地的/home/workspace/gohello-dev目录
git clone -b dev git@192.168.0.12:godev/gohello.git /home/workspace/gohello-dev
  • 拉取
复制代码
# 拉取并自动合并
git pull origin
# 拉取并自动合并,拉取远程dev分支然后合并到本地temp分支
git pull origin master:temp
# 拉取,不自动合并
git fetch origin master:temp
  • 推送
复制代码
# 推送本地dev分支到远程test分支。如果远程仓库没有test分支,将自动创建
git push origin dev:test
相关推荐
鱼骨不是鱼翅2 小时前
Git原理及使用
git
不是光头 强4 小时前
使用idea 将一个git分支的部分记录合并到git另一个分支
git
dotnet905 小时前
windows 11 下git软件提交正常,idea git提交总提示需要token
java·git·intellij-idea
小新在学习18 小时前
GitHub+Git新手使用说明
git·github
算家计算21 小时前
Windows/macOS/Linux三平台Git安装避坑指南
人工智能·git
longze_721 小时前
Git使用git graph插件回滚版本
git
大A崛起1 天前
Gitlab-CI实现组件自动推送
ci/cd·gitlab·github
magic_kid_20101 天前
如何将 git 远程 URL 从 https 更改为 ssh
运维·git·ssh
越来越无动于衷1 天前
GitLab 社区版 10.8.4 安装、汉化与使用教程
gitlab