配置本地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
相关推荐
无限进步_11 小时前
【C语言&数据结构】对称二叉树:镜像世界的递归探索
c语言·开发语言·数据结构·c++·git·算法·visual studio
qq_54702617913 小时前
Git 使用指南
git
XiaoHu020715 小时前
Linux多线程(详细全解)
linux·运维·服务器·开发语言·c++·git
*才华有限公司*16 小时前
RTSP视频流播放系统
java·git·websocket·网络协议·信息与通信
juelianhuayao17 小时前
Git错误提交后如何快速删除本次commit
git
chen<>17 小时前
Git原理与应用
大数据·git·elasticsearch·svn
小兔崽子去哪了17 小时前
Git 专题
git
金米kk18 小时前
git pull时报错Your local changes to the following files would…的解决办法
git
超级罗伯特18 小时前
git一次性完成仓库下载及所有分支获取
git·git仓库拉取
BUTCHER518 小时前
Git 基础命令
git