如何上传项目到github/gitlab?

简介: 如何上传项目到github/gitlab?

前提


  • git bash工具
  • github账号

准备项目


1、在github上创建一个项目,然后git clone到本地。

2、将本地的项目放到和这个文件夹中

上传项目


git add


git add README.md //文件添加到仓库

git add . //不但可以跟单一文件,还可以跟通配符,更可以跟目录。一个点就把当前目录下所有未追踪的文件全部add了

绑定用户


$ git config user.name "myysophia"
$ git config user.email "2324234234234@126.com"

git config –global 参数,有了这个参数,表示你这台机器上所有的Git仓库都会使用这个配置,当然你也可以对某个仓库指定的不同的用户名和邮箱。

将local的公钥加入github的秘钥管理中


公钥就是那个用来加密的数字,这也就是为什么你在本机生成了公钥之后,要上传到github的原因。从github发回来的,用那公钥加密过的数据,可以用你本地的私钥来还原。dd1caa581b4a4b3590a47914e94dc85d.png

在生成github tocken


有了这个token就不用你每次push输入密码了。02ca7146aa414d0d9af3157aae56c8e6.png

参考:https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token

建立本地仓库


$ git commit -m "init"
[main 761dc09] init
 10 files changed, 278 insertions(+)
 create mode 100644 master1/Vagrantfile
 create mode 100644 master1/install.sh
 create mode 100644 master1/reload-k8s-cls.sh
 create mode 100644 master1/startk8s.sh
 create mode 100644 node/Vagrantfile
 create mode 100644 node/install.sh
 create mode 100644 node/reload-k8s-cls.sh
 create mode 100644 shutdown.sh
 create mode 100644 startk8s.sh
git remote add origin1 git@github.com:myysophia/vagrant-init-k8s-cls.git //关联远程仓库
git push -u origin1 master //把本地库的所有内容推送到远程库上
error: src refspec master does not match any
error: failed to push some refs to 'github.com:myysophia/vagrant-init-k8s-cls.git'
git remote -v
origin  https://github.com/myysophia/vagrant-init-k8s-cls.git (fetch)
origin  https://github.com/myysophia/vagrant-init-k8s-cls.git (push)
origin1 git@github.com:myysophia/vagrant-init-k8s-cls.git (fetch)
origin1 git@github.com:myysophia/vagrant-init-k8s-cls.git (push)
https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token

解决报错


stackoverflow最高赞使用这个方法解决了这个问题。第二高赞使用的是git push -f origin master。好像首次push都会有这个问题

$ git pull --rebase origin main
From https://github.com/myysophia/vagrant-init-k8s-cls
 * branch            main       -> FETCH_HEAD
Current branch main is up to date.
$ git push origin main
Enumerating objects: 16, done.
Counting objects: 100% (16/16), done.
Delta compression using up to 4 threads
Compressing objects: 100% (14/14), done.
Writing objects: 100% (14/14), 3.70 KiB | 946.00 KiB/s, done.
Total 14 (delta 5), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (5/5), done.
To https://github.com/myysophia/vagrant-init-k8s-cls.git
   cf957eb..761dc09  main -> main

https://stackoverflow.com/questions/24114676/git-error-failed-to-push-some-refs-to-remote

git rebase


https://morningspace.github.io/tech/git-merge-stories-6/

查看项目


yeah 上传成功了,快来赞一个吧

https://github.com/myysophia/vagrant-init-k8s-cls

604758c95c284116a2729d486c6b426a.png

参考


https://zhuanlan.zhihu.com/p/193140870

上传代码到gitlab


git init
git remote add origin http://10.50.10.71/wangxu0318/chot-rabbitmq-k8s-chart.git 
git add .
git commit -m "chartdemo"     
git push -u origin master

遇到的问题


[1] git push


执行 git push -u -f origin master 提示需要输入密码,不管是输入gitlab的登录密码还是服务器密码都不行。 看来gitlab 不支持这种验证方式。

gitlab 公钥添加


06629aca50144fc6ad54503928cef8d9.png

gitlab gcp key


这个现在还不会等玩会了再来。6f01748499d2447db650ac8a91915bb8.png

[2] git push 提示项目分支被保护


修改项目保护机制。de39d442cf954e79a19791d6c0a8a3a5.png

[3] 首次git push报错


报错如下:

/home/scripts/etl]$git push
git: /usr/local/greenplum-loaders-4.3.16.1/lib/libz.so.1: no version information available (required by git)
The authenticity of host '10.50.10.71 (10.50.10.71)' can't be established.
RSA key fingerprint is c8:d9:8c:ae:6b:fd:f7:6c:ae:06:17:b5:16:f1:08:a8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.50.10.71' (RSA) to the list of known hosts.
To git@10.50.10.71:wangxu0318/etl-tools.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@10.50.10.71:wangxu0318/etl-tools.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'Note about
fast-forwards' section of 'git push --help' for details.

解决:

git pull --rebase origin master

git pull = git fetch + git merge FETCH_HEAD 
git pull --rebase =  git fetch + git rebase FETCH_HEAD

什么是git rebase

https://blog.csdn.net/weixin_42310154/article/details/119004977

相关实践学习
容器服务Serverless版ACK Serverless 快速入门:在线魔方应用部署和监控
通过本实验,您将了解到容器服务Serverless版ACK Serverless 的基本产品能力,即可以实现快速部署一个在线魔方应用,并借助阿里云容器服务成熟的产品生态,实现在线应用的企业级监控,提升应用稳定性。
云原生实践公开课
课程大纲 开篇:如何学习并实践云原生技术 基础篇: 5 步上手 Kubernetes 进阶篇:生产环境下的 K8s 实践 相关的阿里云产品:容器服务 ACK 容器服务 Kubernetes 版(简称 ACK)提供高性能可伸缩的容器应用管理能力,支持企业级容器化应用的全生命周期管理。整合阿里云虚拟化、存储、网络和安全能力,打造云端最佳容器化应用运行环境。 了解产品详情: https://www.aliyun.com/product/kubernetes
目录
相关文章
|
1月前
|
人工智能 文字识别 异构计算
关于github开源ocr项目的疑问
小白尝试Python OCR学习,遇到报错。尝试Paddle OCR部署失败,Tesseract OCR在Colab误操作后恢复失败。EasyOCR在Colab和阿里天池Notebook成功,但GPU资源不足。其他平台部署不顺,决定使用WebUI或阿里云轻应用。求教OCR项目部署到本地及简单OCR项目推荐。
29 2
|
1月前
|
人工智能 自然语言处理 iOS开发
『GitHub项目圈选19』推荐5款本周 让人爱不释手 的开源项目
『GitHub项目圈选19』推荐5款本周 让人爱不释手 的开源项目
|
1月前
|
存储 Web App开发 人工智能
『GitHub项目圈选18』推荐5款本周 超实用 的开源项目
『GitHub项目圈选18』推荐5款本周 超实用 的开源项目
|
1月前
|
人工智能 物联网 机器人
『GitHub项目圈选17』推荐5款本周 火火火 的AI开源项目
『GitHub项目圈选17』推荐5款本周 火火火 的AI开源项目
207 1
|
1月前
|
JSON 搜索推荐 程序员
『GitHub项目圈选15』推荐5款本周 深受程序员喜爱 的开源项目
『GitHub项目圈选15』推荐5款本周 深受程序员喜爱 的开源项目
|
1月前
|
人工智能 自然语言处理 NoSQL
『GitHub项目圈选13』推荐5款本周 让人爱不释手 的开源项目
『GitHub项目圈选13』推荐5款本周 让人爱不释手 的开源项目
|
1月前
|
SQL NoSQL Linux
『GitHub项目圈选11』推荐5款本周 深受开发人员青睐 的开源项目
『GitHub项目圈选11』推荐5款本周 深受开发人员青睐 的开源项目
|
1月前
|
存储 人工智能 API
『GitHub项目圈选10』推荐5款本周 实用给力 的开源项目
『GitHub项目圈选10』推荐5款本周 实用给力 的开源项目
|
1月前
|
自然语言处理 Cloud Native 前端开发
『GitHub项目圈选16』推荐5款本周 大佬狂爱 的开源项目
『GitHub项目圈选16』推荐5款本周 大佬狂爱 的开源项目
|
1月前
|
人工智能 文字识别 自然语言处理
『GitHub项目圈选12』推荐5款本周 深受追捧 的AI开源项目
『GitHub项目圈选12』推荐5款本周 深受追捧 的AI开源项目
178 1