gitlab 和 github 仓库操作

gitlab 和 github 仓库操作

1、创建公钥

# 1.在自己linux系统上执行
ssh-keygen -t ed25519 -C "ssh-key"

# 2.查看公钥
cat ~/.ssh/id_xxx.pub

2、将公钥复制在gitlab网站上去

复制公钥到 个人信息-> Preferences -> SSH Keys

最后点击保存确定就可以 git clone xxx了

3、下载好项目后需要切换分支

4、gitlab 项目操作说明

1、全局设置

git config --global user.name "天堑"  && git config --global user.email "wenxu.he@dingxiang-inc.com"

// github
git config --global user.name "天堑"  && git config --global user.email "1915300275@qq.com"

2、创建一个新的仓库

git clone ssh://git@dev.dingxiang-inc.com:2022/wenxu.he/ot-eye.git
cd ot-eye
git switch -c main
touch README.md
git add README.md
git commit -m "add README"
git push -u origin main

3、压入现有文件夹

cd existing_folder
git init --initial-branch=main
git remote add origin ssh://git@dev.dingxiang-inc.com:2022/wenxu.he/ot-eye.git
git add .
git commit -m "Initial commit"
git push -u origin main

4、压入现有的仓库 ***!!!

cd existing_repo
git remote rename origin old-origin
git remote add origin ssh://git@dev.dingxiang-inc.com:2022/wenxu.he/ot-eye.git
git push -u origin --all
git push -u origin --tags

5、现有上传完整流程 第一次上传

# 从无到有 第一次上传
cd ot-eye
git init 
git remote add origin ssh://git@dev.dingxiang-inc.com:2022/wenxu.he/ot-eye.git
git add .
git commit -m "frist upload"
git branch -M master
git push -u origin master
# 确保有.git
# git clone ssh://git@dev.dingxiang-inc.com:2022/wenxu.he/ot-eye.git
git add .
git commit -m "Initial commit"
git remote rename origin old-origin
git remote add origin ssh://git@dev.dingxiang-inc.com:2022/wenxu.he/ot-eye.git
git push -u origin --all
git push -u origin --tags

# 一步到位
git add . && git commit -m "Initial commit" && git remote rename origin old-origin && git remote add origin ssh://git@dev.dingxiang-inc.com:2022/wenxu.he/ot-eye.git && git push -u origin --all && git push -u origin --tags

6、更新项目代码

# 查看是否有更新
git status 
git add .
git commit -m "update"
git push

# 一步到位
git add . && git commit -m "update" && git push

7、创建分支

git branch second

# 切换到分支
git checkout second
git add . && git commit -m "new branch"

# 上传新分支的代码
git push origin second

# 下载新分支的代码
git pull origin second

5、github项目管理

git git config --global user.name <your-name> #输入你github的用户名
git config --global user.email <your-email> #输入你的邮箱
#创建ssh key
ssh-keygen -t rsa -C "1915300275@qq.com"

# 复制公钥
cat ~/.ssh/id_rsa.pub

# 回到github网址,依次选择:点击自己头像下的Settings-->SSH and GPG keys –> New SSH key”,随便填个title,然后把刚刚复制的内容黏贴上去就可以了。

5.1 在项目目录操作

# 从无到有 第一次上传
git init 
git remote add origin ssh://git@dev.dingxiang-inc.com:2022/shuhai.hu/docker-images.git
git add .
git commit -m "frist upload"
git branch -M master
git push -u origin master

# 一步到位
git add . && git commit -m "frist upload" && git branch -M master && git push -u origin master

5.2 更新代码

# 一步到位
git add . && git commit -m "update" && git push
git add . && git commit -m "无聊更新了一下" && git push

# 拉取代码
git remote add upstream git@github.com:NineSunTaoist/offer-exam.git
git fetch upstream && git merge upstream/master

5.3 切换历史版本

# 查看历史版本
git log

# 排序HEAD查看历史版本
git reflog
# 恢复到上一条指令所选的ID版本
git reset --hard [commit_ID]

# HEAD可以用来替换commit_id,HEAD指向的版本是当前版本,上一个版本就是HEAD^ ,上上一个版本就是HEAD^^ ,往上100个版本写成HEAD~100。

# 查看最新版本修改的内容
git log --stat
git show [commit_id]

5.4 git 打标签

# 查看标签
git tag
git tag -l

# 打上附属标签
git tag -a v2.0 -m "OT-Phantom version 2.0"

# 删除标签
git tag -d v2.0

# 推送标签
git push origin v2.0

# 删除远程仓库的标签
git push origin :refs/tags/v2.0
git push origin --delete v2.0

# 推送所有
git push

打标签参考连接:

https://git-scm.com/book/zh/v2/Git-%E5%9F%BA%E7%A1%80-%E6%89%93%E6%A0%87%E7%AD%BE

5.5 git 设置默认分支

# 显示项目有哪些分支
git remote show origin

# 设置一个分支为默认分支  无效
git branch --set-upstream-to=origin/TianQian TianQian
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值