1、本地Git和GitHub的链接(通过SSH Key配置)
1.1注册GitHub账号,安装Git (window系统用msysgit)
1.2本地配置用户名和邮箱
git config --global user.name ”yourusername”
git config--global user.email ”youremail”
cat ~/.gitconfig
注意:git config --global 参数,有了这个参数,表示你这台机器上所有的Git仓库都会使用这个配置,当然你也可以对某个仓库指定的不同的用户名和邮箱。

1.3通过命令 git init 把当前目录变成git可以管理的仓库
例如:

这时候你当前G:/test目录下会多了一个.git的目录,这个目录是Git来跟踪管理版本的,没事千万不要手动乱改这个目录里面的文件,否则,会把git仓库给破坏了

1.4生成SSH Key
1.4.1运行
ssh-keygen -t rsa -C"你的邮箱"
1.4.2用户主目录/.ssh/下有两个文件,id_rsa是私钥,id_rsa.pub是公钥

1.5登录GitHub,打开"SSH Keys"页面

1.6测试ssh key是否成功
使用命令“ssh -T git@github.com”,再输入“yes”。
如果出现You’ve successfully authenticated, but GitHub does not provide shell access 。这就表示已成功连上GitHub。
2、远程库与本地库之间的操作:
(注意:在获取前一定要确定自己当前的位置)
2.1远程库-->本地库
$ git clone git@github.com:LiShenglin111/Darling.git
(git clone:从远程克隆一份到本地
git@github.com:LiShenglin111/Darling.git :我的SSH)
以后获取用 git pull origin master
2.2本地库-->远程库
2.2.1本地库关联远程库:
$ git remote add origin git@github.com:LiShenglin111/Darling.git
2.2.2推送master分支的所有内容
(1)本地创建文本test.txt
(2)输入:$ git add text.txt
(3)输入:$ git commit -m"添加新文件"
(4)输入:$ git push -u origin master
第一次使用加上了-u参数,是推送内容并关联分支。
推送成功后就可以看到远程和本地的内容一模一样,下次只要本地作了提交,就可以通过命令:
$ git push origin master
把最新内容推送到Github
网友评论