如何上传项目到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

相关实践学习
深入解析Docker容器化技术
Docker是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化,容器是完全使用沙箱机制,相互之间不会有任何接口。Docker是世界领先的软件容器平台。开发人员利用Docker可以消除协作编码时“在我的机器上可正常工作”的问题。运维人员利用Docker可以在隔离容器中并行运行和管理应用,获得更好的计算密度。企业利用Docker可以构建敏捷的软件交付管道,以更快的速度、更高的安全性和可靠的信誉为Linux和Windows Server应用发布新功能。 在本套课程中,我们将全面的讲解Docker技术栈,从环境安装到容器、镜像操作以及生产环境如何部署开发的微服务应用。本课程由黑马程序员提供。     相关的阿里云产品:容器服务 ACK 容器服务 Kubernetes 版(简称 ACK)提供高性能可伸缩的容器应用管理能力,支持企业级容器化应用的全生命周期管理。整合阿里云虚拟化、存储、网络和安全能力,打造云端最佳容器化应用运行环境。 了解产品详情: https://www.aliyun.com/product/kubernetes
目录
相关文章
|
7月前
|
人工智能 JavaScript 前端开发
Github 2024-10-28 开源项目周报 Top15
本周GitHub热门项目涵盖Svelte、Open Interpreter、PowerShell等,涉及Web开发、AI助手、自动化工具等领域,Python、JavaScript为主流语言,展现开源技术活跃生态。(239字)
696 19
|
7月前
|
人工智能 JavaScript 前端开发
Github 2024-11-04 开源项目周报 Top14
本周GitHub热门项目涵盖屏幕截图转代码、网页监控、低代码开发等。Python与TypeScript主导,亮点项目包括AI生成代码工具、开源社交应用Bluesky及机器人框架LeRobot,展现AI与自动化技术的快速发展趋势。
392 15
|
7月前
|
人工智能 JavaScript Docker
Github 2024-11-11 开源项目周报 Top15
本周GitHub热门项目涵盖多领域:Python与TypeScript领跑,包括屏幕截图转代码、本地文件共享、PDF处理、AI开发代理等。亮点项目如screenshot-to-code、LocalSend、OpenHands及Diagrams,兼具创新与实用性,广受开发者关注。
836 13
|
7月前
|
人工智能 算法 JavaScript
Github 2024-10-14 开源项目周报 Top14
本周GitHub热门项目共14个,Python项目占7席。涵盖算法实现、生成式AI、金融分析、目标检测等领域,包括TheAlgorithms系列、OpenBB金融平台、Ultralytics YOLO11、Manim动画框架等,展现开源技术多元发展态势。
269 8
|
7月前
|
人工智能 Rust JavaScript
Github 2024-10-07 开源项目周报 Top15
本周GitHub热门项目共15个,Python项目占比最高达7个。榜首为Python算法实现集合TheAlgorithms/Python,Star数超17万;其他亮点包括Godot游戏引擎、OpenBB金融平台、ToolJet低代码框架及新兴AI相关项目如Crawl4AI、Llama Stack等,涵盖游戏、金融、AI、理财等多个领域。
308 4
|
7月前
|
人工智能 Rust 算法
Github 2024-09-30 开源项目周报 Top15
本周GitHub热门项目揭晓:Python主导,AutoGPT居首,涵盖AI、编程、数学动画等领域,助力开发者探索前沿技术。
270 4
|
7月前
|
人工智能 JavaScript 前端开发
Github 2024-09-16 开源项目周报 Top14
本周GitHub热门项目涵盖Python、TypeScript、Go等语言,React居首。亮点包括微软PowerToys、Node版本管理器、AI证件照工具HivisionIDPhotos及端侧大模型MiniCPM等。
254 2
|
7月前
|
Rust JavaScript 安全
Github 2024-09-02 开源项目周报 Top13
本周GitHub热门项目涵盖AI、开发工具与开源替代品。包括Notion替代AppFlowy、Airtable替代NocoDB、云平台Coolify及可观察性平台OpenObserve等,涉及Python、TypeScript、Rust等语言,聚焦效率、隐私与自动化。
420 1
|
8月前
|
人工智能 编解码 JSON
不看后悔!GitHub 开源 MultiTalk .8k star 强大的人语音+图像绑定项目
MultiTalk 是 GitHub 上的开源项目,具备音频驱动、多人对话视频生成功能。支持多路音频与图像绑定,实现高同步唇动与角色互动,适用于教学、虚拟人及短视频创作,已获 8k 星标。
843 1
|
8月前
|
安全 数据可视化 项目管理
精品,Github 5000+ star,小型研发团队必备商业开源项目
DooTask 是一款开源在线项目任务管理工具,具备文档协作、流程图、任务分发、IM沟通等功能,支持私有部署与数据加密,已在 GitHub 获得 5000+ 星标,适合中小团队提升协作效率。
507 0