【git】将本地文件上传到github

安装git

选择一个文件夹作为git仓库,cd到文件夹输入

c 复制代码
git init

文件夹出现.git文件夹,该文件夹默认为隐藏文件夹,设置为不隐藏

在cmd中输入

c 复制代码
ssh-keygen -t rsa -C "xxx@xxx.com"

该邮箱为github邮箱,然后一路enter出现以下

在本地用户文件夹找到.ssh,打开id_rsa.pub复制获得key

到github创建key

复制刚才本地文件中的key到key中

输入以下添加用户名和邮箱,使用github用户名和邮箱

c 复制代码
git config user.name "要修改的名字"
c 复制代码
git config user.email "要修改的邮箱"

关联Git本地仓库和Git远程仓库,origin后为github仓库地址

c 复制代码
git remote add origin https://github.com/xxx/123.git

添加本文件夹下所有文件到本地仓库

c 复制代码
git add .

查看当前哪些文件已添加

c 复制代码
git status

提交到本地仓库

c 复制代码
git commit -m "upload file"

先尝试push,会弹出github的授权,按步骤授权即可

c 复制代码
git pull --rebase origin main

将刚刚本地提交的文件上传到远程仓库上,main是分支名字

c 复制代码
git push origin main

要删除本地仓库直接删除.git文件夹即可

查看所有分支

c 复制代码
git branch -a

切换分支

c 复制代码
git checkout main

查看日志,由上到下为最新到最旧的log commit后为本次提交的哈希值

c 复制代码
git log

查看所有远端仓库

c 复制代码
git remote  -v

切换本地和远端仓库关联

c 复制代码
git remote set-url origin https://github.com/xx/xx.git (新地址)

从远端仓库拉取文件到本地仓库,除了REDEME以外都会拉取下来

c 复制代码
git pull

回滚提交,可以通过git log查看某一提交操作的哈希值,本回滚为指定哈希值事件的逆操作

c 复制代码
git revert <commit-hash>
相关推荐
1***81531 天前
Git游戏开发案例
git
likuolei1 天前
Git 工作区、暂存区和版本库
数据库·git
知行力1 天前
【GitHub每日速递 20251119】免费开源全学段数学教材,打破教育资源获取壁垒!附文件合并及下载攻略
github
whysqwhw1 天前
kotlin-7
github
whysqwhw1 天前
kotlin-5
github
whysqwhw1 天前
kotlin-6
github
HAPPY酷1 天前
git配置及使用
git
sg_knight1 天前
IntelliJ IDEA 实用插件:GitToolBox 使用指南
java·ide·git·intellij-idea·插件·gittoolbox
青靴1 天前
Git Hooks 实现 CI/CD 进阶实践 -- 根据实际需求添加功能
git·elasticsearch·ci/cd
LiuYaoheng1 天前
Git配置SSH Key到GitHub的详细教程
git·ssh·github