今天重新学习了一下git环境的配置,mark一下。
首先我们需要下载git,地址:点击打开链接,下载之后按照步骤安装就可以。安装好了之后,我们右键一下,能够看到git init,git bash等命令,这就说明安装成功了。接着,我们看一下怎么使用git。
以gitcafe为例,我们试着在gitcafe上面使用git。登陆gitcafe,点击账户设置,进入ssh公钥管理,在这里我们需要输入我们的公钥,当然,现在我们还没有。
开始生成公钥和私钥:
右键git bash,在命令行里面输入命令:
ssh-keygen -t rsa -C "your@gmail.com" -f ~/.ssh/gitcafe
接着会出现下面的提示:
$ ssh-keygen -t rsa -C "your_email@youremail.com" -f ~/.ssh/gitcafe Generating public/private rsa key pair. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /c/Users/username/.ssh/gitcafe. Your public key has been saved in /c/Users/username/.ssh/gitcafe.pub. The key fingerprint is: 15:81:d2:7a:c6:6c:0f:ec:b0:b6:d4:18:b8:d1:41:48 your_email@youremail.com
提示输入密码,输入你的密码并且记住。
这样我们生成的公钥和私钥,进入C:\Users\ColdCoder\.ssh 你会发现新建了两个文件:gitcafe和gitcafe_pub 我们把gitcafe_pub打开,之后,将里面的内容复制到刚才看到的gitcafe公钥管理页面里面。这样,公钥设置好了。
接着,也是很重要的一步,我们需要在C:\Users\ColdCoder\.ssh 下面新建一个文件config,输入:
Host gitcafe.com www.gitcafe.com IdentityFile ~/.ssh/gitcafe
这一步很重要,如果不做,我们在之后的使用origin管理远程仓库的时候会产生没有权限进入远程仓库的错误!
好了,现在我们开始测试通过ssh能不能登陆gitcaf
右键git bash,输入命令:
ssh -T git@gitcafe.com -i ~/.ssh/gitcafe
如果是第一次连接的话,会出现以下警告,不用担心,输入 yes 按回车就可以了。
The authenticity of host 'gitcafe.com (50.116.2.223)' can't be established. #RSA key fingerprint is 84:9e:c9:8e:7f:36:28:08:7e:13:bf:43:12:74:11:4e. #Are you sure you want to continue connecting (yes/no)?
中间会提示你输入 passphrase 口令。
Enter passphrase for key '/c/Users/username/.ssh/gitcafe':
最后,如果连接成功的话,会出现以下信息。
Hi username! You've successfully authenticated, but GitCafe does not provide shell access
好啦,现在ssh配置好了,但是有什么用呢?gitcafe连接远程仓库有三种方式;https ,ssh, git(只读),https链接的时候,我们需要输入用户名密码,比较麻烦,大多数情况下我们使用ssh方式链接远程仓库,所以我们需要配置ssh。
接着,我们设置全局变量:
git config --global user.name "name"
git config --global user.email your@email
设置origin:
git remote add origin git@gitcafe.com:name/test.git
本人理解:origin其实就是你远程仓库地址的别名,使用origin就不用每次输入地址那么麻烦!
创建本地仓库:
mkdir test cd test git init touch README.md git add README.md git commit -m 'first commit' git remote add origin git@gitcafe.com:name/test.git git push origin master
如果出现下面的错误:
说明你的.ssh/文件夹下面没有config文件,参考上文说的如何建立config文件。
好啦,这样就实现可把本地仓库push到远程了。
git命令:git命令
git简易指南:链接