第1步:创建SSH Key。

第2步:登陆GitHub,打开“Account settings”,“SSH Keys”页面:
然后,点“Add SSH Key”,填上任意Title,在Key文本框里粘贴id_rsa.pub文件的内容:

“有了远程仓库,妈妈再也不用担心我的硬盘了。”
添加远程库:已经在本地创建了一个Git仓库后,又想在GitHub创建一个Git仓库,并且让这两个仓库进行远程同步,这样,GitHub上的仓库既可以作为备份,又可以让其他人通过该仓库来协作
登陆GitHub,在右上角找到“Create a new repo”按钮,创建一个新的仓库;
在Repository name填入learngit,其他保持默认设置,点击“Create repository”按钮,成功创建一个新的Git仓库:

在本地的learngit仓库下运行命令:
# git remote add origin git@github.com:sue6356/learngit.git

下一步,把本地库的所有内容推送到远程库上:
# git push -u origin master

把本地库的内容推送到远程,用git push命令,实际上是把当前分支master推送到远程。
由于远程库是空的,第一次推送master分支时,加上了-u参数,Git不但会把本地的master分支内容推送的远程新的master分支,还会把本地的master分支和远程的master分支关联起来,在以后的推送或者拉取时就可以简化命令。
推送成功后,可以在GitHub页面中看到远程库的内容和本地一模一样:

要克隆一个仓库,首先必须知道仓库的地址,然后使用git clone命令克隆。
Git支持多种协议,包括https,但通过ssh支持的原生git协议速度最快。
多人协作1:
[root@system1 learngit]# echo "edit from system1" >> readme.txt
[root@system1 learngit]# git add readme.txt
[root@system1 learngit]# git commit -m "edit from system1"
[root@system1 learngit]# git push origin master

多人协作2:
[root@system2 learngit]# git pull


让Git显示颜色,会让命令输出看起来更醒目:
#git config --global color.uitrue
网友评论