起步
git配置用户名和邮。如果不同用户、不同项目配置时可以不加global。
git config --global user.name "name"
git config --global user.email "xx@gmail.com"
创建仓库
- 直接在本地初始化仓库。
# 进入项目目录
git init
- 从远程仓库克隆(ssh方式配置密钥)
git clone ‘仓库地址’
提交合并
- 添加文件到暂存区
# 添加当前所有修改或添加的文件
git add .
- 提交到仓库
git commit -m"提交信息"
- 代码合并
git merge '其他分支'
# 变基合并
git rebase '其他分支'
- 拉取和推送代码
# 拉取
git fetch
# 拉取合并
git pull
# 推送
git push
- 从某个提交版本复制合并到当前版本
git cherry-pick 版本号
分支
- 新建分支
# 基于当前分支新建分支
git checkout -b '分支名称'
- 切换分支
git checkout '分支名称'
- 没有建立与远程仓库关联,推送或拉取远程代码失败时
git branch --set-upstream branch-name origin/branch-name
自己工作中一般使用流程
- 分配任务,创建开发分支
# 切换到发版分支
git checkout qa
git pull
git checkout -b dev-CTF-8888
- 写完代码
git add .
git commit '提交信息'
- 合并代码(有冲突解决冲突)
git ckeckout qa
git pull
git ckeckout dev-CTF-8888
git rebase qa
git push -f
- 提交请求合并(pr),结束。