git和github的使用指南

目录

1.git初始化本地仓库

2.远程仓库

3.如何将自己的代码上传到远程仓库的某一个分支


1.git初始化本地仓库

在项目目录中初始化 Git 仓库:

bash 复制代码
cd your-project-directory
git init

将文件添加到暂存区:

bash 复制代码
git add .    //添加所有文件
git add <file-name>    //添加单个文件

提交更改

bash 复制代码
git commit -m "Your commit message"

上传到远程仓库

bash 复制代码
git push origin main

2.远程仓库

1.将本地仓库与远程仓库关联:

bash 复制代码
git remote add origin <repository-url>

2.从远程仓库克隆到本地:

bash 复制代码
git clone <repository-url>

一般来说1,2步骤如果是初次的化执行第二个就行,无需建立本地仓库

拉取最新代码

bash 复制代码
git pull origin main

查看远程分支

bash 复制代码
git branch -r

切换目标分支

bash 复制代码
git checkout <branch-name>

拉取指定分支代码

bash 复制代码
git pull origin <branch-name>

3.如何将自己的代码上传到远程仓库的某一个分支

完整步骤

bash 复制代码
//如需克隆某个分支的代码可以改成git clone -b <branch-name> <repository-url>
git clone <repository-url>    //克隆仓库
cd repository                 //进入仓库
git add <file-name>           //提交更改到暂存区
git commit -m "Your commit message"    //将暂存区的文件合并到本地仓库
git push origin <branch-name>          //上传到远程仓库的某个分支,如果该分支不存在会自动创建

如果无法克隆仓库的代码,要先把git的ssh公钥在github中配置

相关推荐
louisgeek2 小时前
Git submodule 子模块
git
imDwAaY2 小时前
6篇文章讲清楚Git:Git 实用技巧:暂存现场、挑选提交与定位 Bug (5/6)
git·后端
u1301302 小时前
GitHub 热榜项目:日榜(2026-09-28)
人工智能·github
imDwAaY2 小时前
6篇文章讲清楚Git:Git 团队开发实践:从 Pull Request 到版本发布 (6/6)
git·后端
miofly4 小时前
GitHub 日榜趋势速报 | 2026-09-29
开源·github
AlfredZhao4 小时前
已提交过的文件夹,如何从 GitHub 中删除
github
@呱呱爱学习13 小时前
2026年09月28日 | 呱呱AI日报】GitHub 发布 Copilot WSL 教程,介绍在 Ubuntu 中运行编程 Agent
人工智能·github·copilot
誰能久伴不乏14 小时前
看懂 Git 团队协作全流程:分支、提交、PR、rebase 到底在干嘛
git
阿里嘎多学长16 小时前
2026-09-28 GitHub 热点项目精选
开发语言·程序员·github·代码托管
程序员清风16 小时前
vLLM 实战:用 OpenAI 兼容接口部署本地大模型推理服务
开源·github·vllm