配置本地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
相关推荐
星谐3 小时前
GitX智能版本控制助手:告别Git命令行,让版本控制更高效
git
错把套路当深情4 小时前
Git 常用命令大全
git
向上_503582918 小时前
解决git提交冲突
git
学习使我健康8 小时前
Git Submodule 深度避坑指南
git
Mapleay10 小时前
git notes
git
zhougl99610 小时前
非root用户,链接ssh,并上传git
运维·git·ssh
qq_4523962311 小时前
【工程实战】第九篇:持续集成 —— Jenkins 与 GitLab CI:构建无人值守的自动化流水线
ci/cd·gitlab·jenkins
muddjsv19 小时前
Git 代码同步与协作的核心命令全解析
git
历程里程碑21 小时前
2. Git版本回退全攻略:轻松掌握代码时光机
大数据·c++·git·elasticsearch·搜索引擎·github·全文检索
果然_1 天前
为什么你的 PR 总是多出一堆奇怪的 commit?90% 的人都踩过这个 Git 坑
前端·git