1. 安装 brew install git
查看版本 git --version
2. 配置用户名和用户邮箱
git config --global user.name "bigen.dong"
git config --global user.email "1134018901@qq.com"
3. 生成秘钥
命令:ssh-keygen -t rsa -C "1134018901@qq.com"
秘钥目录:/Users/当前电脑用户/.ssh
id_rsa 私钥,保存于本地
id_rsa.pub 公钥,需要将里面内容上传到远端仓库
4. 向github添加公钥,Settings > SSH and GPG keys
5. 初始化仓库
具体操作:
-
git clone git@github.com:saiwaiwunong/saiwaiwunong.git /wwwroot/test
git push -u origin master
git push origin master -
git init
git remote add origin git@gitlab.com:saiwaiwunong_/science_tool.git
git add -A
git commit -am 'file'
git push -u origin master
小技巧:
- 提交所有的文件一次性
git add -A
git commit -a -m 'push all file' || git commit -am 'push all file'
-
查看本地仓库
git remote -v -
普通操作
git add index.php
git commit -m 'file'
分支管理
1. git checkout -b dev //创建dev分支,并且切换到dev分支
2. git branch //查看当前所属分支名称,确认是dev分支
3. touch index.html
4. git add index.html
5. git commit -m 'update file'
6. git checkout master //切换到主分支
7. git merge dev //合并分支
网友评论