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

相关推荐
fliter18 小时前
从零开始,自己造一个可执行文件压缩器
github
UTF_819 小时前
一次NSMutableAttributedString误用的思考
ios·面试·github
wh_xia_jun19 小时前
Git 分支合并操作备忘录
git
满天星830357720 小时前
【Git】原理及使用(三)(分支管理)
linux·git
zhang_adrian1 天前
【使用Github Copilot自动按规范文档生成全部代码】
人工智能·github·copilot
像风一样的男人@1 天前
warning: could not find UI helper ‘git-credential-manager-ui‘
git·ui
代钦塔拉1 天前
Git & GitHub 从入门到精通:全流程实战教程
git·github
阿里嘎多学长1 天前
2026-05-30 GitHub 热点项目精选
开发语言·程序员·github·代码托管
晚风吹红霞1 天前
Linux下的趣味编程 —— 进度条、Git版本控制与GDB调试实战
linux·运维·git
xlq223221 天前
7.git
git