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

相关实践学习
通过Ingress进行灰度发布
本场景您将运行一个简单的应用,部署一个新的应用用于新的发布,并通过Ingress能力实现灰度发布。
容器应用与集群管理
欢迎来到《容器应用与集群管理》课程,本课程是“云原生容器Clouder认证“系列中的第二阶段。课程将向您介绍与容器集群相关的概念和技术,这些概念和技术可以帮助您了解阿里云容器服务ACK/ACK Serverless的使用。同时,本课程也会向您介绍可以采取的工具、方法和可操作步骤,以帮助您了解如何基于容器服务ACK Serverless构建和管理企业级应用。 学习完本课程后,您将能够: 掌握容器集群、容器编排的基本概念 掌握Kubernetes的基础概念及核心思想 掌握阿里云容器服务ACK/ACK Serverless概念及使用方法 基于容器服务ACK Serverless搭建和管理企业级网站应用
目录
打赏
0
0
0
0
49
分享
相关文章
【够用就好002】外行第一次发布github项目仓库
#deepseek#自学 记录外行学习代码的历程 今天是上传自己的工具代码到github仓库,一直以来是伸手党克隆别人的项目,今天在deepseek的辅导下上传自己的内容。
|
3月前
|
如何操作github,gitee,gitcode三个git平台建立镜像仓库机制,这样便于维护项目只需要维护一个平台仓库地址的即可-优雅草央千澈
如何操作github,gitee,gitcode三个git平台建立镜像仓库机制,这样便于维护项目只需要维护一个平台仓库地址的即可-优雅草央千澈
248 69
如何操作github,gitee,gitcode三个git平台建立镜像仓库机制,这样便于维护项目只需要维护一个平台仓库地址的即可-优雅草央千澈
vscode推送项目到github仓库故障解决1
本文介绍了如何优雅解决本地仓库与远程仓库历史记录不一致的问题,并提供避免未来问题的最佳实践。核心在于理解问题根源(如历史记录差异和常见原因),采用推荐的解决方案(先本地初始化再关联远程仓库),并遵循一致的工作流程、团队协作规范及熟悉 Git 命令。通过强制推送或合并无关历史记录等方式处理现有冲突,同时养成良好习惯以预防类似问题。
java9到java17的新特性学习--github新项目
本文宣布了一个名为"JavaLearnNote"的新GitHub项目,该项目旨在帮助Java开发者深入理解和掌握从Java 9到Java 17的每个版本的关键新特性,并通过实战演示、社区支持和持续更新来促进学习。
178 3
git使用之如何将一套代码同时推送至github|gitee|gitcode|gitlab等多个仓库-含添加ssh-优雅草央千澈完美解决-提供整体提交代码
git使用之如何将一套代码同时推送至github|gitee|gitcode|gitlab等多个仓库-含添加ssh-优雅草央千澈完美解决-提供整体提交代码
147 16
git使用之如何将一套代码同时推送至github|gitee|gitcode|gitlab等多个仓库-含添加ssh-优雅草央千澈完美解决-提供整体提交代码
Jenkins持续集成GitLab项目 GitLab提交分支后触发Jenkis任务 持续集成 CI/CD 超级详细 超多图(二)
Jenkins持续集成GitLab项目 GitLab提交分支后触发Jenkis任务 持续集成 CI/CD 超级详细 超多图(二)
160 0
|
8月前
|
【事故】记一次意外把公司项目放到GitHub并被fork,如何使用DMCA下架政策保障隐私
在一次意外中,作者因三年前将测试代码遗忘在GitHub上而遭遇了代码被他人fork的问题。为解决这一危机,作者详细介绍了如何通过GitHub的DMCA下架通知流程安全删除敏感代码,包括处理私人信息和商标侵权的具体步骤。本文不仅提供了实用的操作指南,还强调了及时响应的重要性,帮助读者避免类似风险
206 1
【事故】记一次意外把公司项目放到GitHub并被fork,如何使用DMCA下架政策保障隐私
Jenkins持续集成GitLab项目 GitLab提交分支后触发Jenkis任务 持续集成 CI/CD 超级详细 超多图(一)
Jenkins持续集成GitLab项目 GitLab提交分支后触发Jenkis任务 持续集成 CI/CD 超级详细 超多图(一)
372 0
Github 2024-08-26 开源项目周报Top15
根据Github Trendings的统计,本周共有15个项目上榜。以下是按开发语言汇总的项目数量:Python项目8个,TypeScript、C++ 和 Rust 项目各2个,Jupyter Notebook、Shell、Swift 和 Dart 项目各1个。其中,RustDesk 是一款用 Rust 编写的开源远程桌面软件,可作为 TeamViewer 的替代品;Whisper 是一个通用的语音识别模型,基于大规模音频数据集训练而成;初学者的生成式人工智能(第2版)则是由微软提供的18门课程,教授构建生成式AI应用所需的知识。
223 1
Github 2024-08-19 开源项目周报Top15
根据Github Trendings的统计,本周(2024年8月19日统计)共有15个项目上榜。按开发语言分类,上榜项目数量如下:Python项目最多,有7项;其次是JavaScript和TypeScript,各有3项;Dart有2项;HTML、PowerShell、Clojure和C++各1项。此外,还介绍了多个热门项目,包括Bootstrap 5、RustDesk、ComfyUI、易采集、Penpot等,涵盖了Web开发、远程桌面、自动化测试、设计工具等多个领域。
180 1
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等