目录

1.注册github账户。
2.下载git命令工具。
3.创建本地git仓库
4.设置账户的SSH 密钥。
5.连接远程github仓库

创建github账户

注册Git地址:https://github.com
下载git工具:https://git-scm.com/downloads

clipboard.png

创建gitgub仓库

登录github后,在右上角,如图所示。
创建github仓库时输入名字即可,其他尽量别动。推荐使用谷歌浏览器,可以自动翻译为中文。
clipboard.png

clipboard.png

谷歌浏览器
clipboard.png

创建本地Git仓库

在桌面右键打开Git Bath here 命令行工具

配置:

git config --global user.name "Your Name"   配置用户名
git config --global user.email "email@example.com"  配置你的邮箱
git config --global push.default matching
git config --global core.quotepath false
git config --global core.editor "vim"

创建一个目录( 不要包含中文 ) mkdir 目录名
进入这个目录(文件夹):cd 目录名
将这个目录变成git可以管理的仓库 git init
这个目录(文件夹)就是本地仓库了

连接远程仓库

设置SSH key:https://github.com/settings/keys

 生成SSH key(密钥):在bash命令行工具组输入  rm -rf ~/.ssh/*
 ssh-keygen -t rsa -b 4096 -C "你的邮箱"

clipboard.png

 回车三次。
 运行: cat ~/.ssh/id_rsa.pub  会得到一串东西

clipboard.png

 复制粘贴到

clipboard.png

在新建的目录下运行:ssh -T git@github.com

如果看到 Hi FrankFang! You've successfully authenticated, but GitHub does not provide shell access.代表我们的SSH key 已经设置成功
首先我们在目录下做一些修改:
如新建一个文件ss.txt ,
在bash中:git status -sb 查看 得到:

$ git status -sb
## No commits yet on master
?? ss.txt

将修改提交到暂存库中,可以用git add 命令

Git add 文件路径 或 Git add .

clipboard.png

将暂存库内的修改提交到本地

 Git commit -m”说明” 

clipboard.png

连接远程库

clipboard.png
输入:

  git remote add origin git@github.com:你的用户名/git仓库名.git

clipboard.png

 可以运行git remote -v 查看本地仓库权限

clipboard.png

如果如上图显示有fetch和push权限,说明已经进行了连接
接下来,将本地修改推送到远端仓库:

  git push -u origin master

现在已经推送到远端,可以去github上查看一下

clipboard.png


如有疑问可在下方留言,或参考其他文档,若有错误,也欢迎在下方留言。


苏飞
1 声望1 粉丝

git:github.com/SequoiaKing


下一篇 »
git 分支操作