使用git上传github仓库

文章目录

使用git上传github仓库

1 安装和设置 Git
Git官网,直接下载安装Git即可。在本地需要上传的代码文件夹中右击Open Git Bash here。


2 安装好 Git 之后,在命令行中输入以下命令来设置你的 GitHub 用户名和电子邮件

python 复制代码
git config --global user.name "你的用户名"
git config --global user.email "你的邮箱"
git config -l ###检查是否设置成功


3.在本地初始化你的项目

python 复制代码
git init

初始化后可以在文件夹中看到.git文件,如果没有发现就是没有打开隐藏文件。

4.添加文件到你的 Git 仓库

将该文件夹中所有文件添加到仓库

python 复制代码
git add *

5.提交

使用以下命令来提交:

python 复制代码
git commit -m "first commit"

6 修改分支名字并连接 GitHub 仓库

这里注意要选择HTTP,如果没有设置公钥的话。

可以看出分支名字和自己新建仓库不一样,这里是master,仓库里是main

所有改成main

python 复制代码
git branch -m master main

连接仓库并推送

python 复制代码
git remote add origin https://github.com/LittleBeanBun/CUDA.git
git push -u orgin main

最后登录一下git刷新一下页面即可。

如果中途遇到问题,显示分支已存在,可以使用一下命令移除之后再进行添加。

python 复制代码
git remote remove origin

小结

有个视频讲解的很清楚,推荐查看。视频链接:手把手教你把自己的项目利用git上传到GitHub!!!

相关推荐
可乐_不渴3 小时前
【Linux】 项目自动化构建工具makefile&& 版本管理Git&&第一个程序
linux·git·自动化·1024程序员节
wflynn3 小时前
GitHub 今日推荐|dquickts:能暂停、能存档的 QuickJS
开源·github·c·durable-execution·embeddable·hibernation
lzx_0026 小时前
Linux 开发工具(六) 版本管理器git的简单使用
git·1024程序员节
miofly6 小时前
GitHub 今日推荐|gpu-unlock-ada:Ada 显卡张量算力翻倍解锁
开源·github
jiangliushi67 小时前
GPT-6.1 Sol 免费用:git status 里中文文件名变成一串数字乱?条命令改好
git·codex·1024程序员节
miofly7 小时前
GitHub 周榜趋势速报 | 2026-10-25
开源·github
miofly7 小时前
GitHub 日榜趋势速报 | 2026-10-25
开源·github
u1301309 小时前
GitHub 热榜项目:日榜(2026-10-24)
人工智能·github·1024程序员节
保卫大狮兄16 小时前
2小时,我搭了一套仓库出入库管理系统:收货、领料、退料、库存全打通!
wms·github·仓库·入库
沙蒿同学16 小时前
不引 Ghostscript:我用纯 Go 给 PDF 做了一场「压缩手术」
前端·后端·github