美文网首页树莓派我的收藏
在树莓派上搭建git

在树莓派上搭建git

作者: 露华浓 | 来源:发表于2015-10-05 11:08 被阅读2806次

1.首先安装git客户端和服务器

sudo apt-get install git-core

2.在树莓派上安装ssh服务

sudo apt-get install ssh

3.查找树莓派IP

在树莓派的命令行输入命令:
ifconfig

eth0 Link encap:Ethernet HWaddr xx:xx:xx:xx:xx:xx
inet addr:192.168.1.127 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:793 errors:0 dropped:0 overruns:0 frame:0
TX packets:306 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:254072 (248.1 KiB) TX bytes:40903 (39.9 KiB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:2 errors:0 dropped:0 overruns:0 frame:0
TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:100 (100.0 B) TX bytes:100 (100.0 B)

inet addr:后加深部分即为IP地址。

4.添加git用户组和用户

首先创建git目录:
sudo adduser --system --shell /bin/bash --gecos 'git version control by pi' --group --home /home/git git
接着修改git密码:
sudo passwd git
输入新的 UNIX 密码:
重新输入新的 UNIX 密码:
然后将用户切换至git:
su git
输入刚才设置的git密码,切换成功。

5.增加一个新的仓库(Git Repository)

首先进入git目录:
cd /home/git
然后创建文件并初始化仓库。
mkdir first.git cd first.git git --bare init
回显显示:初始化空的 Git 版本库于 /home/git/first.git/

6.push 代码到git上

首先,更改路径到你之前初始化的git仓库(或初始化一个新的)。
加入一个新的远程主机(*你的IP地址没有中括号)
git remote add pi git@[your IP]:/home/git/test.git
现在你要做的就是add你的代码,commit然后push。
git add . git commit -am "Initial" git push pi master
如果你得到了一个类似这样的消息”authenticity of host …”只需要输入”yes”然后继续就可以了。理想情况下,如果一切正常,你的Git仓库已经搭建在你的树莓派上了。

7.使用git服务器

如果你想要测试一下,试着clone你的仓库到你的Windows机器上。首先更改路径到你希望存储clone的地方(一个空文件夹),然后通过命令行(或git bash),运行:
git clone git@[your IP]:/home/git/test.git

相关文章

网友评论

    本文标题:在树莓派上搭建git

    本文链接:https://www.haomeiwen.com/subject/ixigcttx.html