记录一些使用Git的基本步骤,适合初学者入门:
- 安装Git
- 从官网下载并安装Git(https://git-scm.com/)
- 在命令行中验证安装:
git --version
- 配置Git
- 设置用户名:
git config --global user.name "Your Name"
- 设置邮箱:
git config --global user.email "your_email@example.com"
- 创建新仓库
- 创建新文件夹:
mkdir my_project
- 进入文件夹:
cd my_project
- 初始化仓库:
git init
- 添加文件到暂存区
- 创建文件:
touch README.md
- 添加文件:
git add README.md
- 添加所有文件:
git add .
- 提交更改
- 提交:
git commit -m "Initial commit"
- 查看状态和历史
- 检查状态:
git status
- 查看提交历史:
git log
- 创建和切换分支
- 创建新分支:
git branch feature-branch
- 切换到新分支:
git checkout feature-branch
- 或者一步完成:
git checkout -b feature-branch
- 合并分支
- 切回主分支:
git checkout main
- 合并分支:
git merge feature-branch
- 处理远程仓库
- 添加远程仓库:
git remote add origin <repository-url>
- 推送到远程:
git push -u origin main
- 从远程拉取:
git pull origin main
- 克隆现有仓库
- 克隆仓库:
git clone <repository-url>
- 清空远程仓库的方法
1 git clone https://github.com/KeL1n1995/KeL1n1995.github.io.git
2 cd KeL1n1995.github.io
3 git rm -r *
4 git commit -m "Clear repository"
5 git push origin main
- 更新远程仓库的方法
1git init
2git remote set-url origin https://github.com/AniKeLin/Hugo.git
3git add .
4git commit -m "update"
5git push