使用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!!!

相关推荐
亦世凡华、35 分钟前
静态网站部署:如何通过GitHub免费部署一个静态网站
经验分享·github·github pages·站点部署
modelmd2 小时前
配置代理服务器访问github、google
github
xianyinsuifeng9 小时前
FastAPI + OpenAI 模型 的 GitHub 项目结构模板
github·fastapi
仍然探索未知中10 小时前
Git分支管理
git
小妖66611 小时前
windows11 安装好后右键没有 git bash 命令
git
只做开心事11 小时前
Git 多人协作
git
freejackman11 小时前
Git从入门到精通
git·gitee·gitlab·github
Silence4Allen13 小时前
零基础用 Hexo + Matery 搭建博客|Github Pages 免费部署教程
github·hexo·博客搭建·matery
qianmoQ13 小时前
GitHub 趋势日报 (2025年05月16日)
github
兔子坨坨14 小时前
pycharm连接github(详细步骤)
windows·git·学习·pycharm·github