一、设置和配置
1.初始化一个新的仓库:
git init
 
2.克隆(Clone)一个远程仓库到本地:
git clone <repository_url>
 
3.配置用户信息:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
 
二、基本操作
1.查看文件状态:
git status
 
2.添加文件到暂存区:
git add <file1> <file2> ...
 
3.提交更改到版本库:
git commit -m "Your commit message"
 
4.查看提交日志:
git log 
三、分支操作
1.创建新分支:
git branch <branch_name>
 
2.切换到指定分支:
git checkout <branch_name>
或
git switch <branch_name>
 
3.创建并切换到新分支:
git checkout -b <new_branch_name>
或
git switch -c <new_branch_name>
 
 1732  git branch test_1  -- 创建新分支test_1
 1733  git branch -r --查看远程分支
 1734  git checkout test_1 --切换到指定分支test_1
 1735  git status 
 1736  git add.
 1737  git add README.md
 1738  git commit -m "Your commit message"
 1739  git push -u origin master  --此时推送的是master分支,README.md文件并没有修改
 1740  git push -u origin test_1    --此时推送的是test_1分支,README.md文件已经修改
 
 后续在gitlab会出现push request,可以手动创建merge request,并同意; 

4.合并分支:
git merge <branch_name>
 
5.删除分支:
git branch -d <branch_name>
 
 
四、远程操作
1.查看远程仓库信息:
git remote -v 
2.添加远程仓库:
git remote add <remote_name> <repository_url> 
3.从远程仓库拉取更新:
git pull <remote_name> <branch_name>
 
4.推送本地更改到远程仓库:
git push <remote_name> <branch_name>
 
5.查看远程分支:
git branch -r 
五、撤销和重置

1.撤销工作区的更改:
git restore <file>
或
git checkout -- <file>
举例子:git checkout -- README.md 
2.撤销暂存区的更改:
git reset HEAD <file>
举例子:git reset HEAD README.md 
3.回滚到之前的提交:
git reset --hard <commit_hash> 
六、其他操作
1.查看修改过的文件:
git diff 
2.查看分支合并图:
git log --graph --oneline --all 
3.查看帮助信息:
git --help 
                



















