将项目上传到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密钥,格式为:

复制代码
git@github.com:<用户名>/<仓库名>.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
相关推荐
相与还13 小时前
IDEA和GIT实现cherry pick拣选部分变更到新分支
git·elasticsearch·intellij-idea
Moonbit18 小时前
月报 Vol.04 : 新增 async test 与 async fn main 语法,新增 lexmatch 表达式
后端·github·编程语言
逛逛GitHub18 小时前
发现 4 个贼好玩的 GitHub 项目,相当给劲儿。
github
悟能不能悟20 小时前
用cmd命令修改适配器ip
网络·tcp/ip·github
刘志辉20 小时前
git指令
git
whysqwhw21 小时前
kuiklyui core-ksp ios
github
whysqwhw21 小时前
kuiklyui core-ksp 鸿蒙
github
CoderJia程序员甲21 小时前
GitHub 热榜项目 - 日榜(2025-10-12)
ai·github·开源项目·github热榜
whysqwhw21 小时前
kuikly core-ksp 安卓
github
Tfly__1 天前
Ubuntu 20.04 安装Aerial Gym Simulator - 基于 Gym 的无人机强化学习仿真器
linux·人工智能·ubuntu·github·无人机·强化学习·运动规划