将项目上传到github

1.通过 Git Bash 进入到需要上传的项目所在的目录中,然后执行以下命令:

复制代码
git init

此时项目文件就会新建一个.git文件夹。

2.将项目所有文件添加到 Git 仓库中。执行以下命令:

复制代码
git add .

该命令会将项目中所有未被忽略的文件都添加到 Git 仓库中。

  1. 提交代码到 Git 仓库。执行以下命令:

    git commit -m "Initial commit"

4.其中-m参数后面的内容是提交说明,用于描述这次提交的内容。

将本地 Git 仓库与远程 GitHub 仓库关联起来。执行以下命令:

复制代码
git remote add origin <GitHub 仓库地址>

其中<GitHub 仓库地址>是指您在第一步中创建的新仓库的地址,可在新建的github仓库中找到,http 格式通常为:

复制代码
https://github.com/<用户名>/<仓库名>.git

也可以使用SSH密钥,格式为:

复制代码
[email protected]:<用户名>/<仓库名>.git

如果报错:git问题error: remote origin already exists.

如果你clone下来一个别人的仓库,在此基础上完成你的代码,推送到自己的仓库可能遇到如下问题:

error: remote origin already exists.表示远程仓库已存在。

因此你要进行以下操作:

1、先输入git remote rm origin 删除关联的origin的远程库

2、关联自己的仓库 git remote add origin https://gitee.com/xxxxxx.git

3、最后git push origin master,这样就推送到自己的仓库了。

将本地 Git 仓库中的代码推送到 GitHub 仓库中。执行以下命令:

复制代码
git push -u origin master
相关推荐
m0_749317521 小时前
vscode里如何用git
ide·git·vscode
Hello.Reader1 小时前
Git 安装全攻略Linux、macOS、Windows 与源码编译
linux·git·macos
OpenTiny社区2 小时前
开源之夏报名倒计时3天!还有9个前端任务有余位,快来申请吧~
前端·github
王景程2 小时前
SELinux是什么以及如何编写SELinux策略
git·github
Chuncheng's blog2 小时前
如何基于Mihomo Party http端口配置git与bash命令行代理
git·http·bash
Tom Boom3 小时前
Git常用命令完全指南:从入门到精通
大数据·git·elasticsearch·docker·自动化测试框架
宝桥南山4 小时前
DeepSeek - 尝试一下GitHub Models中的DeepSeek
microsoft·ai·微软·c#·github·.net
不爱学英文的码字机器4 小时前
[Git] 文件删除
git
lifeng43216 小时前
在 CentOS 上将 Ansible 项目推送到 GitHub 的完整指南
centos·github·ansible
DZSpace6 小时前
git stash命令用法
git