Git

[Git]Git使用方法

  "Git的一些使用方法记录"

Posted by Stephen.Ri on July 17, 2019

配置SSH公钥

用下面的命令查看~/.ssh目录下有没有fileName.pub文件。

$ cd ~/.ssh
$ ls

如果没有,则用下方命令生成:

$ ssh-keygen

位置可以默认,密码可以留空。

配置用户名和邮箱

每次Git提交时都会引用我们的用户名和邮箱,说明是谁提交的更新。

$ git config --global user.name "Stephen"
$ git config --global user.email stephen@example.com

从远程下载库

$ git clone url
$ git init
$ git add fileName
$ git commit -m "message"
$ git push

上传本地库

$ git init
$ git remote add origin remoteUrl
$ git add .
$ git commit -m "message"
$ git push -u origin master

删除文件

从本地和库中删除

$ git rm fileName

仅从git库中删除,而本地保留

$ git rm --cached fileName