常用 GIT 命令

1)将远程仓库纳入管理

其实就是添加远程仓库,在你已有的本地仓库目录下执行如下命令: (在仓库右上角里SSH 里COPY 地址)

$ git remote add example git@github.com:yourUserId/example.git

或者使用:

$ git remote add example https://github.com/yourUserId/example

 该命令的含义是:在远程添加一个example的仓库,这个远程仓库的url是:https://github.com/yourUserId/example

 

2)拉取远程文件

如果远程仓库中已有文件,就先要将文件拉到本地仓库。如果远程没有文件,就不需要这一步。

$ git pull example
3)将本地文件推到远程仓库
$ vim .gitignore   // 编辑 ignore文件
$ git add yourprojectfiles // 添加已有文件,让git 能够跟踪这些文件
$ git commit -a -m 'Initial Version' // 提交到本地仓库
$ git push example master        // 将本地仓库(master)文件 push 到远程仓库(example)
当你第一次使用Git的clone或者push命令连接GitHub时,会得到一个警告:
The authenticity of host 'github.com (xx.xx.xx.xx)' can't be established.
RSA key fingerprint is xx.xx.xx.xx.xx.
Are you sure you want to continue connecting (yes/no)?
这是因为Git使用SSH连接,而SSH连接在第一次验证GitHub服务器的Key时,需要你确认GitHub的Key的指纹信息是否真的来自GitHub的服务器,输入yes回车即可。

Git会输出一个警告,告诉你已经把GitHub的Key添加到本机的一个信任列表里了:

Warning: Permanently added 'github.com' (RSA) to the list of known hosts.

这个警告只会出现一次,后面的操作就不会有任何警告了。

原文地址:https://www.cnblogs.com/peterwong666/p/11225846.html