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