Overview
1.配置 git
2.基本操作: clone/push/pull
3.分支合并: merge v.s. rebase
4.远程仓库被重命名
配置 git
执行
ssh-keygen -t rsa -C "github的邮箱地址"
一路 enter
(通过ls查看~/.ssh下面的所有内容查看)
将刚刚创建的ssh keys添加到 github 中
1.利用 gedit/cat 命令,查看id_rsa.pub的内容
2.在 GitHub 中,依次点击 Settings -> SSH Keys -> Add SSH Key,将id_rsa.pub文件中的字符串复制进去,注意字符串中没有换行和空格.
再次检查SSH连接情况(在~/.ssh目录下):
输入如下命令
ssh -T git@github.com
看到如下所示,则表示添加成功
Hi 用户名! You’ve successfully authenticated, but GitHub does not provide shell access.
即利用自己的用户名和email地址配置git
git config --global user.name "你的github用户名"
git config --global user.email "你的github邮箱地址"
ps: 为什么配置好了提交代码到远程分之还是要输入密码? clone的时候选择http
基本操作: clone, pull, push
clone: 克隆远程分支到本地
git clone -b my_branch <远程仓库地址>
pull: 将远程代码pull[拉取]到本地
git pull origin branch_name
push: 将本地代码push[推送]到远程
git add yourfilename
git ci -m "说明修改内容, 常见格式: fix xx bug/add xx function/remove xx file"
git push origin branch_name
分支合并: merge v.s. rebase
将分支my_branch合并到master分支
git checkout master
git merge my_branch
git push origin master
远程仓库被重命名
远程仓库被重命名
Terminal
$ git push origin master
显示
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 294 bytes | 294.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
remote: This repository moved. Please use the new location:
remote: https://github.com/tetsu-upstr/JSblog.git
To https://github.com/tetsu-upstr/blog.git
7468063..962d5cd master -> master
输入
$ git remote -v
显示
origin https://github.com/tetsu-upstr/blog.git (fetch)
origin https://github.com/tetsu-upstr/blog.git (push)
Terminal set-url
$ git remote set-url origin https://github.com/tetsu-upstr/JSblog.git
检查更改
$ git remote -v
显示
origin https://github.com/tetsu-upstr/JSblog.git (fetch)
origin https://github.com/tetsu-upstr/JSblog.git (push)
转载请注明来源, from goldandrabbit.github.io