之前说过 git 本地使用记录,再说说 Github 的使用
1. 添加 SSHkey
1 | $ ssh-keygen -t rsa -C "youremail@example.com" # 不需要设密码(这样方便) |
将生成的 SSHkey.pub 公钥 复制到 GitHub 个人账户的 SSH keys 中
2. 克隆 远程库
1 | $ git clone git@github.com/userName/repositoryName # 复制 远程库 到 本地 |
3. 设置远程仓库
1 | $ git remote add origin git@github.com/userName/repositoryName # 设置 远程仓库 名为 origin |
4. 将本地分支推送远程分支
1 | $ git push -u orgin master # 第一次推到远程仓库,把当前分支推到远程仓库 master 分支 |
5. 关联本地分支于远程分支
即设置本地分支 对应 远程哪个分支
1 | # 设置 本地分支XX 对应 远程分支YY |
在第一次git push -u orgin master中的-u参数就是设置 当前分支 对应 远程 master 分支
要创建本地仓库和远程仓库对应的分支,可用以下指令1
2# 创建 本地分支xx ,该分支对应 远程分支YY
$ git checkout -b <本地分支名XX> orgin/<远程分支名YY>
6. 将远程分支拉到本地分支
1 | $ git pull # 根据 当前的本地分支(即 HEAD) 将相对应的 远程分支 拉到本地 |