Linux环境下使用github

最近一段时间以来都在使用svn,git反而有点生疏了。和几个朋友一起计划做项目,linux下做开发,使用github进行版本控制。说来也怪,windows基本不用怎么配置,但是linux就要稍微绕一下路了。

1. 安装前的准备

linux主机一台(我用的是Debain),github账号一个

2. 安装git工具

因为我使用的是apt库,所以只需要执行一下命令就可以了

apt-get install git

需要注意的是,上述的命令是需要管理员权限的。

3. 生成ssh密钥

安装完git之后,如无意外应该可以git clone一个项目了,但是过程中可能会很曲折。与windows不同的是,linux下需要在本机生成密钥,然后将其中的公钥上传到github个人主页上。具体操作如下(此时需要管理员权限)

ssh-keygen -t rsa -C "你的github邮箱地址"

Enter passphrase (empty for no passphrase): [Type a passphrase]

Enter same passphrase again: [Type passphrase again]

然后输入密码,就生成成功了。然后切换到 /root/.ssh, 如无意外,你会看到有三个文件 id_rsa  id_rsa.pub  known_hosts,其中的id_rsa.pub就是公钥,我们需要把它放到github上。

4. 添加公钥到github

打开个人github主页--->setting--->SSH and GPG keys, 然后点击New SSH key。Title可以任意写,将id_rsa.pub里面的内容全部复制到Key表单里面。

如无意外,应该部署成功了。不妨拿一个项目来试试。

5. 另外,使用git的时候,要配置 git config --global user.name 或者git config --global user.email。如果你的git版本是2.0以上,还要设置一些东西,不然会报错如下

warning: push.default is unset; its implicit value is changing in

Git 2.0 from 'matching' to 'simple'. To squelch this message

and maintain the current behavior after the default changes, use:

    git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

    git config --global push.default simple

这段话的意思是,matching参数是git2.0以下的默认行为,执行git push操作的时候如果没有指定分支,则会push本地所有分支到远程仓库中相对应的分支。而到了2.x,默认行为是simple,执行git push 没有指定分支的时候,只会push当前所在分支到远程仓库。

所以,你必要指定其中一个参数。(当然,可以随时改变这个参数的)

至此,搭建完成。

你可能感兴趣的:(Linux环境下使用github)