本地项目上传到GitHub

本文档因使用实际项目提交做为案例,故使用xxx等字符进行脱敏,同时隐藏了部分输出,已实际项目和命令行输出为准

0、 Git 安装与GitHub注册

1) 在下述地址下载Git,安装一路默认下一步即可。安装完成后,随便找个文件夹鼠标右键,存在Git GUI HereGit Bash Here 两个选项即可

https://git-scm.com/downloads

2) GitHub注册

访问下方地址,点右上角 sign up进行注册即可。

https://github.com/

1、 本地工程文件初始化

进入到本地工程的文件夹,右键点击Git Bash Here进入命令行窗口,然后输入git init命令。

shell 复制代码
$ git init
Reinitialized existing Git repository in D:/xx/xxx/.git/

执行完成后,文件夹中会多一个.git文件夹,如果看不到该文件夹,可能是隐藏了,电脑文件资源管理器上方查看 菜单里,将隐藏的项目勾上即可。

2、 代码添加到仓库

执行 git add 命令将代码添加到仓库。这里说的仓库,只是本地仓库,不是GitHub仓库。因为工程文件夹里面会有 targetideaeclipse等IDE的配置文件等,所以这一步可以手动挑选需要上传的文件夹和文件,也可以写一个.gitignore文件添加忽略规则

1、 .gitignore

txtfile 复制代码
.classpath
.project
.settings/
target/

2、 git add

shell 复制代码
$ git add src/
$ git add pom.xml
$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   pom.xml
        ......(省略)

add之后可以通过git status命令查看,输出的Changes to be committed会将添加到仓库待提交的文件列举出来。

3、代码提交

使用 git commit命令提交代码,-m参数是一般常用参数,代表注释。

shell 复制代码
$ git commit -m "first commit"
[master (root-commit) d0bbe42] first commit
 11 files changed, 248 insertions(+)
 create mode 100644 pom.xml
 ......(省略)

4、 远程仓库创建及代码push

点击左上角按钮创建

或头像下菜单创建

点击后跳转到页面,填写信息即可。

创建完成后进入到仓库,把这个仓库的地址复制下来

复制了地址之后,回到命令行,输入命令行push代码到GitHub(这里xxx都是脱敏和谐掉的,以实际为准,下同)

shell 复制代码
$ git remote add origin https://github.com/xxx/xxxx.git

接着就可以pushGitHub

shell 复制代码
$ git push -u origin master

这里会让你输入用户名和密码,但是我在提交的时候,会遇到输了账号和密码,但是验证不通过的情况,输出如下

Logon failed, use ctrl+c to cancel basic credential prompt.

Username for 'https://github.com': 我的用户名

remote: Support for password authentication was removed on August 13, 2021.

remote: Please see https://docs.github.com/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.

fatal: Authentication failed for 'https://github.com/xxx/xxx.git/'

根据 参照 https://blog.csdn.net/weixin_43452467/article/details/121704661 生成了token并修改命令行。重新push

shell 复制代码
$ git remote set-url origin https://我的token@github.com/xxx/xxxx.git
$ git push -u origin master
fatal: unable to access 'https://我的token@github.com/xxx/xxxx.git': Failed to connect to github.com port 443: Timed out

又根据 参照 https://blog.csdn.net/qq_37284798/article/details/127806254才可正常push

shell 复制代码
$ git config --global --unset http.proxy
$ git config --global --unset https.proxy
$ git push -u origin master
Enumerating objects: 30, done.
Counting objects: 100% (30/30), done.
Delta compression using up to 12 threads
Compressing objects: 100% (16/16), done.
Writing objects: 100% (30/30), 4.42 KiB | 1.47 MiB/s, done.
Total 30 (delta 0), reused 0 (delta 0)
remote:
remote: Create a pull request for 'master' on GitHub by visiting:
remote:      https://github.com/xxx/xxxx/pull/new/master
remote:
To https://github.com/xxx/xxxx.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

至此,本地项目就pushGitHub

5、 默认分支的设置

按照上述命令行,我们是以master分支提交的,而GitHub默认是main分支,这样的话,仓库里面就会有两个分支,有时候需要把默认分支替换。

1、 全局修改

2、 单仓储修改


我这里还把main 分支删了,下面截图是删了以后的

选择main分支进行删除即可

参考文献

https://blog.csdn.net/qq_37284798/article/details/127806254

https://blog.csdn.net/weixin_43452467/article/details/121704661

相关推荐
程序媛Dev15 分钟前
还在 SSH 连服务器敲 SQL?我用 Sealos 把数据库管理后台搬进了浏览器!
开源·github
淡酒交魂1 小时前
「Flink」业务搭建方法总结
大数据·数据挖掘·数据分析
mask哥1 小时前
详解flink java基础(一)
java·大数据·微服务·flink·实时计算·领域驱动
TDengine (老段)1 小时前
TDengine IDMP 高级功能(4. 元素引用)
大数据·数据库·人工智能·物联网·数据分析·时序数据库·tdengine
livemetee2 小时前
Flink2.0学习笔记:Flink服务器搭建与flink作业提交
大数据·笔记·学习·flink
猫头虎3 小时前
猫头虎AI分享|一款Coze、Dify类开源AI应用超级智能体Agent快速构建工具:FastbuildAI
人工智能·开源·github·aigc·ai编程·ai写作·ai-native
Onion_993 小时前
学习下Github上的Android CICD吧
android·github
zhang98800003 小时前
储能领域大数据平台的设计中如何使用 Hadoop、Spark、Flink 等组件实现数据采集、清洗、存储及实时 / 离线计算,支持储能系统分析与预测
大数据·hadoop·spark
老蒋新思维3 小时前
存量竞争下的破局之道:品牌与IP的双引擎策略|创客匠人
大数据·网络·知识付费·创客匠人·知识变现
Lx3525 小时前
Hadoop日志分析实战:快速定位问题的技巧
大数据·hadoop