Git 速查手册
·2 min read
创建空分支
checkout --orphan empty_branch
git rm -rf .
echo "# new project" > README.md
git add README.md
git commit -m "init files"
git push origin empty_branch
删除本地分支和远程分支
git branch -d branch_name // 可选择 -D ,忽略错误
git push origin -d branch_name
把当前分支重命名为master
git branch -m master
把代码推送到远程仓库
git push -f origin master
分支代码合并到 master 主分支
# 切换到分支
git checkout branch_name
# 使用git pull 把分支代码pull下来
git pull
# 切换到主分支
git checkout master
# 把分支的代码merge到主分支
git merge branch_name
# git push推上去ok完成,现在 你自己分支的代码就合并到主分支上了
git push
查询配置信息 & 初始化
# 列出当前配置
git config --list
# 列出repository配置
git config --local --list
# 列出全局配置
git config --global --list
# 列出系统配置
git config --system --list
# 配置用户名
git config --global user.name "your name"
# 配置用户邮箱
git config --global user.email "youremail@github.com"
# 配置解决冲突时使用哪种差异分析工具,比如要使用vimdiff
git config --global merge.tool vimdiff
# 配置git命令输出为彩色的
git config --global color.ui auto
# 配置git使用的文本编辑器
git config --global core.editor vi