GitHub使用教程详解
- GitHub是为开发者提供的Git仓库的托管服务,这是一个让开发者与同事共享代码的场所;
- GitHub和Git的区别,GitHub和Git是完全不同的两个东西,在Git中开发者将代码存入名为Git仓库的资料库中,并加以使用而GitHub则是在网络中提上提供Git仓库的一项服务;
- GitHub上公开的代码都由Git进行管理;
一、Github账号注册
1、登录Github官网,进行账号注册、并创建仓库
- 为实验效果,创建“岳不群(老板)”、“令狐冲(员工)”两个Github账号
二、创建本地库、并初始化
1、岳不群(老板)在Linux终端创建"huashan(华山)"本地库
[root@localhost ~]# mkdir huashan ///创建目录
[root@localhost ~]# cd huashan
[root@localhost huashan]# git init ///初始化本地库
初始化空的 Git 仓库于 /root/huashan/.git/
2、在本地库里创建"jianfa(剑法)"文本、并提交至版本库
[root@localhost huashan]# cat jianfa.txt ///
华山剑法、填下第一!!!
[root@localhost huashan]# git add jianfa.txt
[root@localhost huashan]# git commit -m "jianfa" jianfa.txt
位于分支 master
无文件要提交,干净的工作区
三、创建远程库
1、创建远程库
- 岳不群(老板)在Github创建华山(huashan)远程库
2、把本地库pull推送到远程库
- 获取远程库HTTPS地址
- 回到Linux端huashan本地库,绑定远程库HTTPS地址
[root@localhost huashan]# git remote add origin https://github.com/Yuebuqun-666/huashan.git
[root@localhost huashan]# git remote -v ///查看当前所有HTTPS地址
origin https://github.com/Yuebuqun-666/huashan.git (fetch) ///写回
origin https://github.com/Yuebuqun-666/huashan.git (push) ///推送
四、将本地库推送到远程库
将huashan本地库master分支推送到远程库中
[root@localhost huashan]# git push origin master ///推送命令:git pull origin + 需要推送的分支
Username for 'https://github.com': Yuebuqun-666 ///输入所有者(老板)远程库名
Password for 'https://Yuebuqun-666@github.com': ///远程库密码
对象计数中: 5, 完成.
Delta compression using up to 4 threads. ///推送
压缩对象中: 100% (