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中配置

相关推荐
知行力3 分钟前
【GitHub每日速递 20251219】Claude-Mem:持久内存压缩系统,为Claude Code带来上下文连续性新体验!
github
刘某某.15 分钟前
提交 git 的三种方式
git
薛定e的猫咪1 小时前
覆盖文献到写作全流程!GPT-Academic 多模型学术助手安装与使用指南
人工智能·gpt·github
鸽鸽程序猿1 小时前
【Redis】Java客户端使用Redis
java·redis·github
bigHead-2 小时前
Git 修改远程仓库地址的几种方法
git
杀手不太冷!3 小时前
Jenkins的安装与使用;git clone url的时候,url为http和ssh时候的区别
git·http·jenkins
m0_726365833 小时前
大力学习台灯T6/T6Pro 救砖实战:macOS/Windows 用 mtkclient 从 Fastboot 无限重启完整恢复(含固件下载地址)
python·github·智能硬件
qq_229058014 小时前
GIT使用方法
git
YMGogre4 小时前
Git 多人协作开发
git
Mr.zwX4 小时前
如何用vscode/cursor快速绑定并操作远程Github仓库
ide·vscode·github